Skip to content

Commit

Permalink
test/http: Test how client::make_request() handles provided timeout
Browse files Browse the repository at this point in the history
Two cases to check -- that timing out factory is handled and that timing
out pooled connection is handled.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
  • Loading branch information
xemul committed Jun 26, 2024
1 parent 6a0d906 commit f9aa0e3
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/unit/httpd_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,64 @@ SEASTAR_TEST_CASE(test_client_response_parse_error) {
});
}

SEASTAR_TEST_CASE(test_client_request_send_timeout_cached_conn) {
return seastar::async([] {
loopback_connection_factory lcf(1);
auto ss = lcf.get_server_socket();
promise<> server_started;
future<> server = ss.accept().then([&] (accept_result ar) {
server_started.set_value();
return sleep(std::chrono::seconds(1)).finally([sk = std::move(ar.connection)] {});
});

future<> client = seastar::async([&lcf, &server_started] {
auto cln = http::experimental::client(std::make_unique<loopback_http_factory>(lcf), 1 /* max connections */);
// this request gets handled by server and ...
(void)make_failing_http_request(cln);
server_started.get_future().get();
// ... this should hang waiting for cached connection
auto f2 = cln.make_request(http::request::make("GET", "test", "/test"), [] (const auto& rep, auto&& in) {
return make_exception_future<>(std::runtime_error("Shouldn't happen"));
}, http::reply::status_type::ok, http::experimental::client::clock_type::now() + std::chrono::milliseconds(100));

BOOST_REQUIRE_THROW(f2.get(), httpd::timeout_error);
cln.close().get();
});

when_all(std::move(client), std::move(server)).discard_result().get();
});
}

SEASTAR_TEST_CASE(test_client_request_send_timeout_new_conn) {
return seastar::async([] {
loopback_connection_factory lcf(1);
auto ss = lcf.get_server_socket();
future<> server = ss.accept().discard_result();

class delayed_factory : public loopback_http_factory {
public:
explicit delayed_factory(loopback_connection_factory& f) : loopback_http_factory(f) {}
virtual future<connected_socket> make() override {
return sleep(std::chrono::seconds(1)).then([this] {
return loopback_http_factory::make();
});
}
};

auto client = async([&] {
auto cln = http::experimental::client(std::make_unique<delayed_factory>(lcf));
auto f = cln.make_request(http::request::make("GET", "test", "/test"), [] (const auto& rep, auto&& in) {
return make_exception_future<>(std::runtime_error("Shouldn't happen"));
}, http::reply::status_type::ok, http::experimental::client::clock_type::now() + std::chrono::milliseconds(100));

BOOST_REQUIRE_THROW(f.get(), httpd::timeout_error);
cln.close().get();
});

when_all(std::move(client), std::move(server)).discard_result().get();
});
}

SEASTAR_TEST_CASE(test_client_retry_request) {
return seastar::async([] {
loopback_connection_factory lcf(1);
Expand Down

0 comments on commit f9aa0e3

Please sign in to comment.