Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/boost/redis/impl/setup_request_utils.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ void compose_setup_request(config& cfg)
}

// In any case, the setup request should have the priority
// flag set so it's executed before any other request
// flag set so it's executed before any other request.
// The setup request should never be retried.
request_access::set_priority(cfg.setup, true);
cfg.setup.get_config().cancel_if_unresponded = true;
cfg.setup.get_config().cancel_on_connection_lost = true;
}

void clear_response(generic_response& res)
Expand Down
2 changes: 1 addition & 1 deletion include/boost/redis/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class request {
*
* @param cfg Configuration options.
*/
explicit request(config cfg = config{true, false, true, true})
explicit request(config cfg = config{false, false, true, true})
: cfg_{cfg}
{ }

Expand Down
1 change: 1 addition & 0 deletions test/test_conn_quit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BOOST_AUTO_TEST_CASE(test_async_run_exits)
// Should fail since this request will be sent after quit.
request req3;
req3.get_config().cancel_if_not_connected = true;
req3.get_config().cancel_on_connection_lost = true;
req3.push("PING");

bool c1_called = false, c2_called = false, c3_called = false;
Expand Down
14 changes: 12 additions & 2 deletions test/test_multiplexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,18 @@ void test_cancel_on_connection_lost()
test_item item_written1, item_written2, item_staged1, item_staged2, item_waiting1, item_waiting2;

// Different items have different configurations
// (note that these are all true by default)
item_written1.req.get_config().cancel_if_unresponded = false;
item_written1.req.get_config().cancel_on_connection_lost = true;
item_written2.req.get_config().cancel_if_unresponded = true;
item_written2.req.get_config().cancel_on_connection_lost = true;
item_staged1.req.get_config().cancel_if_unresponded = false;
item_staged1.req.get_config().cancel_on_connection_lost = true;
item_staged2.req.get_config().cancel_if_unresponded = true;
item_staged2.req.get_config().cancel_on_connection_lost = true;
item_waiting1.req.get_config().cancel_if_unresponded = true;
item_waiting1.req.get_config().cancel_on_connection_lost = false;
item_waiting2.req.get_config().cancel_if_unresponded = true;
item_waiting2.req.get_config().cancel_on_connection_lost = true;

// Make each item reach the state it should be in
mpx.add(item_written1.elem_ptr);
Expand Down Expand Up @@ -847,9 +855,10 @@ void test_cancel_on_connection_lost_abandoned()
auto item_staged2 = std::make_unique<test_item>();

// Different items have different configurations
// (note that these are all true by default)
item_written1->req.get_config().cancel_if_unresponded = false;
item_written2->req.get_config().cancel_if_unresponded = true;
item_staged1->req.get_config().cancel_if_unresponded = false;
item_staged2->req.get_config().cancel_if_unresponded = true;

// Make each item reach the state it should be in
mpx.add(item_written1->elem_ptr);
Expand Down Expand Up @@ -938,6 +947,7 @@ void test_reset()
generic_response push_resp;
mpx.set_receive_adapter(any_adapter{push_resp});
test_item item1, item2;
item1.req.get_config().cancel_on_connection_lost = true;

// Add a request
mpx.add(item1.elem_ptr);
Expand Down
36 changes: 36 additions & 0 deletions test/test_setup_request_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ void test_compose_setup()
std::string_view const expected = "*2\r\n$5\r\nHELLO\r\n$1\r\n3\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

void test_compose_setup_select()
Expand All @@ -51,6 +53,8 @@ void test_compose_setup_select()
"*2\r\n$6\r\nSELECT\r\n$2\r\n10\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

void test_compose_setup_clientname()
Expand All @@ -63,6 +67,8 @@ void test_compose_setup_clientname()
expected = "*4\r\n$5\r\nHELLO\r\n$1\r\n3\r\n$7\r\nSETNAME\r\n$11\r\nBoost.Redis\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

void test_compose_setup_auth()
Expand All @@ -78,6 +84,8 @@ void test_compose_setup_auth()
expected = "*5\r\n$5\r\nHELLO\r\n$1\r\n3\r\n$4\r\nAUTH\r\n$3\r\nfoo\r\n$3\r\nbar\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

void test_compose_setup_auth_empty_password()
Expand All @@ -92,6 +100,8 @@ void test_compose_setup_auth_empty_password()
expected = "*5\r\n$5\r\nHELLO\r\n$1\r\n3\r\n$4\r\nAUTH\r\n$3\r\nfoo\r\n$0\r\n\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

void test_compose_setup_auth_setname()
Expand All @@ -108,6 +118,8 @@ void test_compose_setup_auth_setname()
"6\r\nmytest\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

void test_compose_setup_use_setup()
Expand All @@ -127,6 +139,8 @@ void test_compose_setup_use_setup()
"*2\r\n$6\r\nSELECT\r\n$1\r\n8\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

// Regression check: we set the priority flag
Expand All @@ -142,6 +156,27 @@ void test_compose_setup_use_setup_no_hello()
std::string_view const expected = "*2\r\n$6\r\nSELECT\r\n$1\r\n8\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

// Regression check: we set the relevant cancellation flags in the request
void test_compose_setup_use_setup_flags()
{
redis::config cfg;
cfg.use_setup = true;
cfg.setup.clear();
cfg.setup.push("SELECT", 8);
cfg.setup.get_config().cancel_if_unresponded = false;
cfg.setup.get_config().cancel_on_connection_lost = false;

compose_setup_request(cfg);

std::string_view const expected = "*2\r\n$6\r\nSELECT\r\n$1\r\n8\r\n";
BOOST_TEST_EQ(cfg.setup.payload(), expected);
BOOST_TEST(cfg.setup.has_hello_priority());
BOOST_TEST(cfg.setup.get_config().cancel_if_unresponded);
BOOST_TEST(cfg.setup.get_config().cancel_on_connection_lost);
}

// clear response
Expand Down Expand Up @@ -185,6 +220,7 @@ int main()
test_compose_setup_auth_setname();
test_compose_setup_use_setup();
test_compose_setup_use_setup_no_hello();
test_compose_setup_use_setup_flags();

test_clear_response_empty();
test_clear_response_nonempty();
Expand Down