-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP: Warning and test fix #943
Changes from 4 commits
dc3eaad
d507054
cfae058
5ceda4c
995da77
e8de934
98db2f4
f35f6f0
2b43faf
4a96d63
913f7f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -604,6 +604,7 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) { | |
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:8891"); | ||
s.wait(boost::asio::ip::tcp::socket::wait_write); | ||
boost::beast::http::write(s, req); | ||
} | ||
}; | ||
|
@@ -622,6 +623,12 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) { | |
return count_of_status_replies; | ||
}; | ||
|
||
auto wait_for_no_bytes_in_flight = [&](uint16_t max = std::numeric_limits<uint16_t>::max()) { | ||
greg7mdp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while (http_plugin->bytes_in_flight() > 0 && --max) | ||
std::this_thread::sleep_for(std::chrono::milliseconds(5)); | ||
BOOST_CHECK(max > 0); | ||
}; | ||
|
||
|
||
//send a single request to start with | ||
send_4mb_requests(1u); | ||
|
@@ -642,13 +649,15 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) { | |
|
||
//load up some more requests that exceed max | ||
send_4mb_requests(32u); | ||
//make sure got to the point http threads had responses queued | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
//now rip these connections out before the responses are completely sent | ||
connections.clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understood your description right, this is the area that is problematic. Between this line and the line below the http plugin needs to have cleaned up all its ownstanding async_writes. Just closing the socket here does indeed send the FIN but the http threads need time to wake up and handle that error on the async_write to then clear out what's in flight. I wonder if what might work is to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would likely work. I added a check for |
||
wait_for_no_bytes_in_flight(); | ||
//send some requests that should work still | ||
send_4mb_requests(8u); | ||
r = drain_http_replies(); | ||
for (const auto& e : r) { | ||
ilog( "response: ${f}, count: ${c}", ("f", std::string(obsolete_reason(e.first)))("c", e.second)); | ||
} | ||
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::ok], 8u); | ||
} | ||
|
||
|
@@ -684,6 +693,7 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) { | |
for(boost::asio::ip::tcp::socket& c : connections) { | ||
boost::beast::http::response<boost::beast::http::string_body> resp; | ||
boost::beast::flat_buffer buffer; | ||
c.wait(boost::asio::ip::tcp::socket::wait_read); | ||
boost::beast::http::read(c, buffer, resp); | ||
|
||
count_of_status_replies[resp.result()]++; | ||
|
@@ -694,12 +704,19 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) { | |
return count_of_status_replies; | ||
}; | ||
|
||
auto wait_for_no_bytes_in_flight = [&](uint16_t max = std::numeric_limits<uint16_t>::max()) { | ||
while (http_plugin->bytes_in_flight() > 0 && --max) | ||
std::this_thread::sleep_for(std::chrono::milliseconds(5)); | ||
BOOST_CHECK(max > 0); | ||
}; | ||
|
||
|
||
//8 requests to start with | ||
send_requests(8u); | ||
std::unordered_map<boost::beast::http::status, size_t> r = scan_http_replies(); | ||
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::ok], 8u); | ||
connections.clear(); | ||
wait_for_no_bytes_in_flight(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test case has to do with requests in flight, not bytes, so this feels mismatched but maybe it still serves enough of its purpose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A requests in flight would be better and useful to verify in both cases. I'll add it. |
||
|
||
//24 requests will exceed threshold | ||
send_requests(24u); | ||
|
@@ -708,12 +725,17 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) { | |
BOOST_REQUIRE_GT(r[boost::beast::http::status::service_unavailable], 0u); | ||
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::service_unavailable] + r[boost::beast::http::status::ok], 24u); | ||
connections.clear(); | ||
wait_for_no_bytes_in_flight(); | ||
|
||
//requests should still work | ||
send_requests(8u); | ||
r = scan_http_replies(); | ||
for (const auto& e : r) { | ||
ilog( "response: ${f}, count: ${c}", ("f", std::string(obsolete_reason(e.first)))("c", e.second)); | ||
} | ||
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::ok], 8u); | ||
connections.clear(); | ||
wait_for_no_bytes_in_flight(); | ||
} | ||
|
||
//A warning for future tests: destruction of http_plugin_test_fixture sometimes does not destroy http_plugin's listeners. Tests | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this and the
wait_read
below? Why would the socket not be writable here? And if it isn't writable why does it matter before a sync write is issued?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed. I'll remove.