@@ -622,6 +622,23 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {
622622 return count_of_status_replies;
623623 };
624624
625+ auto wait_for_no_bytes_in_flight = [&](uint16_t max = std::numeric_limits<uint16_t >::max ()) {
626+ // bytes_in_flight is only increased when sending a response, need to make sure all requests are done
627+ // so that we can then verify no bytes in flight. If we checked bytes_in_flight in the while loop then it is
628+ // possible we can catch it with 0 bytes in flight even though there are requests still being processed that
629+ // will shortly increase the bytes in flight when they respond to the request.
630+ while (http_plugin->requests_in_flight () > 0 && --max)
631+ std::this_thread::sleep_for (std::chrono::milliseconds (5 ));
632+ BOOST_CHECK (max > 0 );
633+ BOOST_CHECK (http_plugin->bytes_in_flight () == 0 );
634+ };
635+
636+ auto wait_for_requests = [&](uint16_t num_requests, uint16_t max = std::numeric_limits<uint16_t >::max ()) {
637+ while (http_plugin->requests_in_flight () < num_requests && --max)
638+ std::this_thread::sleep_for (std::chrono::milliseconds (5 ));
639+ BOOST_CHECK (max > 0 );
640+ };
641+
625642
626643 // send a single request to start with
627644 send_4mb_requests (1u );
@@ -643,12 +660,16 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {
643660 // load up some more requests that exceed max
644661 send_4mb_requests (32u );
645662 // make sure got to the point http threads had responses queued
646- std::this_thread::sleep_for ( std::chrono::seconds ( 1 ) );
663+ wait_for_requests ( 32u );
647664 // now rip these connections out before the responses are completely sent
648665 connections.clear ();
666+ wait_for_no_bytes_in_flight ();
649667 // send some requests that should work still
650668 send_4mb_requests (8u );
651669 r = drain_http_replies ();
670+ for (const auto & e : r) {
671+ ilog ( " response: ${f}, count: ${c}" , (" f" , std::string (obsolete_reason (e.first )))(" c" , e.second ));
672+ }
652673 BOOST_REQUIRE_EQUAL (r[boost::beast::http::status::ok], 8u );
653674}
654675
@@ -694,12 +715,19 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
694715 return count_of_status_replies;
695716 };
696717
718+ auto wait_for_no_requests_in_flight = [&](uint16_t max = std::numeric_limits<uint16_t >::max ()) {
719+ while (http_plugin->requests_in_flight () > 0 && --max)
720+ std::this_thread::sleep_for (std::chrono::milliseconds (5 ));
721+ BOOST_CHECK (max > 0 );
722+ };
723+
697724
698725 // 8 requests to start with
699726 send_requests (8u );
700727 std::unordered_map<boost::beast::http::status, size_t > r = scan_http_replies ();
701728 BOOST_REQUIRE_EQUAL (r[boost::beast::http::status::ok], 8u );
702729 connections.clear ();
730+ wait_for_no_requests_in_flight ();
703731
704732 // 24 requests will exceed threshold
705733 send_requests (24u );
@@ -708,12 +736,17 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
708736 BOOST_REQUIRE_GT (r[boost::beast::http::status::service_unavailable], 0u );
709737 BOOST_REQUIRE_EQUAL (r[boost::beast::http::status::service_unavailable] + r[boost::beast::http::status::ok], 24u );
710738 connections.clear ();
739+ wait_for_no_requests_in_flight ();
711740
712741 // requests should still work
713742 send_requests (8u );
714743 r = scan_http_replies ();
744+ for (const auto & e : r) {
745+ ilog ( " response: ${f}, count: ${c}" , (" f" , std::string (obsolete_reason (e.first )))(" c" , e.second ));
746+ }
715747 BOOST_REQUIRE_EQUAL (r[boost::beast::http::status::ok], 8u );
716748 connections.clear ();
749+ wait_for_no_requests_in_flight ();
717750}
718751
719752// A warning for future tests: destruction of http_plugin_test_fixture sometimes does not destroy http_plugin's listeners. Tests
0 commit comments