Skip to content

Commit

Permalink
Merge pull request #2231 from AntelopeIO/http_ut_ports
Browse files Browse the repository at this point in the history
[5.0 -> main] improve reliability of `http_plugin_unit_tests` via port workaround
  • Loading branch information
spoonincode authored Feb 9, 2024
2 parents cf7a961 + c37b99e commit 5f5462d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions plugins/http_plugin/tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ BOOST_AUTO_TEST_CASE(test_on_loopback) {

BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {
http_plugin* http_plugin = init({"--plugin=eosio::http_plugin",
"--http-server-address=127.0.0.1:8888",
"--http-server-address=127.0.0.1:8891",
"--http-max-bytes-in-flight-mb=64"});
BOOST_REQUIRE(http_plugin);

Expand All @@ -600,10 +600,10 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {
//we can't control http_plugin's send buffer, but at least we can control our receive buffer size to help increase
// chance of server blocking
s.set_option(boost::asio::socket_base::receive_buffer_size(8*1024));
s.connect(resolver.resolve("127.0.0.1", "8888")->endpoint());
s.connect(resolver.resolve("127.0.0.1", "8891")->endpoint());
boost::beast::http::request<boost::beast::http::empty_body> req(boost::beast::http::verb::get, "/4megabyte", 11);
req.keep_alive(true);
req.set(http::field::host, "127.0.0.1:8888");
req.set(http::field::host, "127.0.0.1:8891");
boost::beast::http::write(s, req);
}
};
Expand Down Expand Up @@ -654,7 +654,7 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {

BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
http_plugin* http_plugin = init({"--plugin=eosio::http_plugin",
"--http-server-address=127.0.0.1:8888",
"--http-server-address=127.0.0.1:8892",
"--http-max-in-flight-requests=16"});
BOOST_REQUIRE(http_plugin);

Expand All @@ -671,10 +671,10 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
auto send_requests = [&](unsigned count) {
for(unsigned i = 0; i < count; ++i) {
boost::asio::ip::tcp::socket& s = connections.emplace_back(ctx, boost::asio::ip::tcp::v4());
boost::asio::connect(s, resolver.resolve("127.0.0.1", "8888"));
boost::asio::connect(s, resolver.resolve("127.0.0.1", "8892"));
boost::beast::http::request<boost::beast::http::empty_body> req(boost::beast::http::verb::get, "/doit", 11);
req.keep_alive(true);
req.set(http::field::host, "127.0.0.1:8888");
req.set(http::field::host, "127.0.0.1:8892");
boost::beast::http::write(s, req);
}
};
Expand Down Expand Up @@ -714,4 +714,7 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
r = scan_http_replies();
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::ok], 8u);
connections.clear();
}
}

//A warning for future tests: destruction of http_plugin_test_fixture sometimes does not destroy http_plugin's listeners. Tests
// added in the future should avoid reusing ports of other tests in http_plugin_unit_tests.

0 comments on commit 5f5462d

Please sign in to comment.