Skip to content

Commit c0937e4

Browse files
authored
Merge branch 'release/1.0' into fix_trace_api_get_trx_block_number
2 parents e850b10 + 8d08494 commit c0937e4

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

plugins/http_plugin/http_plugin.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,14 @@ namespace eosio {
624624
my->plugin_state->update_metrics = std::move(fun);
625625
}
626626

627+
size_t http_plugin::requests_in_flight() const {
628+
return my->plugin_state->requests_in_flight;
629+
}
630+
631+
size_t http_plugin::bytes_in_flight() const {
632+
return my->plugin_state->bytes_in_flight;
633+
}
634+
627635
std::atomic<bool>& http_plugin::listening() {
628636
return my->listening;
629637
}

plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ namespace eosio {
130130

131131
void register_update_metrics(std::function<void(metrics)>&& fun);
132132

133+
size_t requests_in_flight() const;
134+
135+
size_t bytes_in_flight() const;
136+
133137
std::atomic<bool>& listening();
134138
private:
135139
std::shared_ptr<class http_plugin_impl> my;

plugins/http_plugin/tests/unit_tests.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)