mirror of
https://github.com/boostorg/redis.git
synced 2026-01-19 04:42:09 +00:00
Splits read_buffer tests to a separate file (#368)
This commit is contained in:
committed by
GitHub
parent
2bbf0090b5
commit
7750a6b126
@@ -53,6 +53,7 @@ make_test(test_multiplexer)
|
||||
make_test(test_parse_sentinel_response)
|
||||
make_test(test_update_sentinel_list)
|
||||
make_test(test_flat_tree)
|
||||
make_test(test_read_buffer)
|
||||
|
||||
# Tests that require a real Redis server
|
||||
make_test(test_conn_quit)
|
||||
|
||||
@@ -70,6 +70,7 @@ local tests =
|
||||
test_parse_sentinel_response
|
||||
test_update_sentinel_list
|
||||
test_flat_tree
|
||||
test_read_buffer
|
||||
;
|
||||
|
||||
# Build and run the tests
|
||||
|
||||
@@ -210,87 +210,6 @@ BOOST_AUTO_TEST_CASE(issue_233_optional_array_with_null)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(read_buffer_prepare_error)
|
||||
{
|
||||
using boost::redis::detail::read_buffer;
|
||||
|
||||
read_buffer buf;
|
||||
|
||||
// Usual case, max size is bigger then requested size.
|
||||
buf.set_config({10, 10});
|
||||
auto ec = buf.prepare();
|
||||
BOOST_TEST(!ec);
|
||||
buf.commit(10);
|
||||
|
||||
// Corner case, max size is equal to the requested size.
|
||||
buf.set_config({10, 20});
|
||||
ec = buf.prepare();
|
||||
BOOST_TEST(!ec);
|
||||
buf.commit(10);
|
||||
buf.consume(20);
|
||||
|
||||
auto const tmp = buf;
|
||||
|
||||
// Error case, max size is smaller to the requested size.
|
||||
buf.set_config({10, 9});
|
||||
ec = buf.prepare();
|
||||
BOOST_TEST(ec == error_code{boost::redis::error::exceeds_maximum_read_buffer_size});
|
||||
|
||||
// Check that an error call has no side effects.
|
||||
auto const res = buf == tmp;
|
||||
BOOST_TEST(res);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(read_buffer_prepare_consume_only_committed_data)
|
||||
{
|
||||
using boost::redis::detail::read_buffer;
|
||||
|
||||
read_buffer buf;
|
||||
|
||||
buf.set_config({10, 10});
|
||||
auto ec = buf.prepare();
|
||||
BOOST_TEST(!ec);
|
||||
|
||||
auto res = buf.consume(5);
|
||||
|
||||
// No data has been committed yet so nothing can be consummed.
|
||||
BOOST_CHECK_EQUAL(res.consumed, 0u);
|
||||
|
||||
// If nothing was consumed, nothing got rotated.
|
||||
BOOST_CHECK_EQUAL(res.rotated, 0u);
|
||||
|
||||
buf.commit(10);
|
||||
res = buf.consume(5);
|
||||
|
||||
// All five bytes should have been consumed.
|
||||
BOOST_CHECK_EQUAL(res.consumed, 5u);
|
||||
|
||||
// We added a total of 10 bytes and consumed 5, that means, 5 were
|
||||
// rotated.
|
||||
BOOST_CHECK_EQUAL(res.rotated, 5u);
|
||||
|
||||
res = buf.consume(7);
|
||||
|
||||
// Only the remaining five bytes can be consumed
|
||||
BOOST_CHECK_EQUAL(res.consumed, 5u);
|
||||
|
||||
// No bytes to rotated.
|
||||
BOOST_CHECK_EQUAL(res.rotated, 0u);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(read_buffer_check_buffer_size)
|
||||
{
|
||||
using boost::redis::detail::read_buffer;
|
||||
|
||||
read_buffer buf;
|
||||
|
||||
buf.set_config({10, 10});
|
||||
auto ec = buf.prepare();
|
||||
BOOST_TEST(!ec);
|
||||
|
||||
BOOST_CHECK_EQUAL(buf.get_prepared().size(), 10u);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(check_counter_adapter)
|
||||
{
|
||||
using boost::redis::any_adapter;
|
||||
|
||||
102
test/test_read_buffer.cpp
Normal file
102
test/test_read_buffer.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE.txt)
|
||||
*/
|
||||
|
||||
#include <boost/redis/detail/read_buffer.hpp>
|
||||
#include <boost/redis/error.hpp>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
using namespace boost::redis;
|
||||
using detail::read_buffer;
|
||||
using boost::system::error_code;
|
||||
|
||||
namespace {
|
||||
|
||||
void test_prepare_error()
|
||||
{
|
||||
read_buffer buf;
|
||||
|
||||
// Usual case, max size is bigger then requested size.
|
||||
buf.set_config({10, 10});
|
||||
auto ec = buf.prepare();
|
||||
BOOST_TEST_EQ(ec, error_code());
|
||||
buf.commit(10);
|
||||
|
||||
// Corner case, max size is equal to the requested size.
|
||||
buf.set_config({10, 20});
|
||||
ec = buf.prepare();
|
||||
BOOST_TEST_EQ(ec, error_code());
|
||||
buf.commit(10);
|
||||
buf.consume(20);
|
||||
|
||||
auto const tmp = buf;
|
||||
|
||||
// Error case, max size is smaller to the requested size.
|
||||
buf.set_config({10, 9});
|
||||
ec = buf.prepare();
|
||||
BOOST_TEST_EQ(ec, error_code{error::exceeds_maximum_read_buffer_size});
|
||||
|
||||
// Check that an error call has no side effects.
|
||||
BOOST_TEST(buf == tmp);
|
||||
}
|
||||
|
||||
void test_prepare_consume_only_committed_data()
|
||||
{
|
||||
read_buffer buf;
|
||||
|
||||
buf.set_config({10, 10});
|
||||
auto ec = buf.prepare();
|
||||
BOOST_TEST(!ec);
|
||||
|
||||
auto res = buf.consume(5);
|
||||
|
||||
// No data has been committed yet so nothing can be consummed.
|
||||
BOOST_TEST_EQ(res.consumed, 0u);
|
||||
|
||||
// If nothing was consumed, nothing got rotated.
|
||||
BOOST_TEST_EQ(res.rotated, 0u);
|
||||
|
||||
buf.commit(10);
|
||||
res = buf.consume(5);
|
||||
|
||||
// All five bytes should have been consumed.
|
||||
BOOST_TEST_EQ(res.consumed, 5u);
|
||||
|
||||
// We added a total of 10 bytes and consumed 5, that means, 5 were
|
||||
// rotated.
|
||||
BOOST_TEST_EQ(res.rotated, 5u);
|
||||
|
||||
res = buf.consume(7);
|
||||
|
||||
// Only the remaining five bytes can be consumed
|
||||
BOOST_TEST_EQ(res.consumed, 5u);
|
||||
|
||||
// No bytes to rotated.
|
||||
BOOST_TEST_EQ(res.rotated, 0u);
|
||||
}
|
||||
|
||||
void test_check_buffer_size()
|
||||
{
|
||||
read_buffer buf;
|
||||
|
||||
buf.set_config({10, 10});
|
||||
auto ec = buf.prepare();
|
||||
BOOST_TEST_EQ(ec, error_code());
|
||||
|
||||
BOOST_TEST_EQ(buf.get_prepared().size(), 10u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
test_prepare_error();
|
||||
test_prepare_consume_only_committed_data();
|
||||
test_check_buffer_size();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user