Skip to content

Commit

Permalink
test/http: Generalize simple request sending
Browse files Browse the repository at this point in the history
There are several tests that call client::make_request() with some
simple pre-defined request that's supposed to fail. Next patches will
want to do the same, so prepare the helper function in advance.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
  • Loading branch information
xemul committed Jun 26, 2024
1 parent 2a399a7 commit 6a0d906
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tests/unit/httpd_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,12 @@ static void read_simple_http_request(input_stream<char>& in) {
}
}

static future<> make_failing_http_request(http::experimental::client& cln) {
return cln.make_request(http::request::make("GET", "test", "/test"), [] (const http::reply& rep, input_stream<char>&& in) {
return make_exception_future<>(std::runtime_error("Shouldn't happen"));
}, http::reply::status_type::ok);
}

SEASTAR_TEST_CASE(test_client_response_eof) {
return seastar::async([] {
loopback_connection_factory lcf(1);
Expand All @@ -908,10 +914,7 @@ SEASTAR_TEST_CASE(test_client_response_eof) {

future<> client = seastar::async([&lcf] {
auto cln = http::experimental::client(std::make_unique<loopback_http_factory>(lcf));
auto req = http::request::make("GET", "test", "/test");
BOOST_REQUIRE_EXCEPTION(cln.make_request(std::move(req), [] (const http::reply& rep, input_stream<char>&& in) {
return make_exception_future<>(std::runtime_error("Shouldn't happen"));
}, http::reply::status_type::ok).get(), std::system_error, [] (auto& ex) {
BOOST_REQUIRE_EXCEPTION(make_failing_http_request(cln).get(), std::system_error, [] (auto& ex) {
return ex.code().value() == ECONNABORTED;
});

Expand Down Expand Up @@ -940,9 +943,7 @@ SEASTAR_TEST_CASE(test_client_response_parse_error) {
future<> client = seastar::async([&lcf] {
auto cln = http::experimental::client(std::make_unique<loopback_http_factory>(lcf));
auto req = http::request::make("GET", "test", "/test");
BOOST_REQUIRE_EXCEPTION(cln.make_request(std::move(req), [] (const http::reply& rep, input_stream<char>&& in) {
return make_exception_future<>(std::runtime_error("Shouldn't happen"));
}, http::reply::status_type::ok).get(), std::runtime_error, [] (auto& ex) {
BOOST_REQUIRE_EXCEPTION(make_failing_http_request(cln).get(), std::runtime_error, [] (auto& ex) {
return sstring(ex.what()).contains("Invalid http server response");
});

Expand Down

0 comments on commit 6a0d906

Please sign in to comment.