Skip to content

Commit

Permalink
GH-1858 Add better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Nov 6, 2023
1 parent 836ca1a commit 5bb7313
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
28 changes: 20 additions & 8 deletions tests/trx_generator/trx_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,21 @@ namespace eosio::testing {
void http_connection::disconnect() {
int max = 30;
int waited = 0;
while (_sent.load() != _acknowledged.load() && waited < max) {
ilog("http_connection::disconnect waiting on ack - sent ${s} | acked ${a} | waited ${w}",
("s", _sent.load())("a", _acknowledged.load())("w", waited));
for (uint64_t sent = _sent.load(), acknowledged = _acknowledged.load();
sent != acknowledged && waited < max;
sent = _sent.load(), acknowledged = _acknowledged.load()) {
ilog("disconnect waiting on ack - sent ${s} | acked ${a} | waited ${w}",
("s", sent)("a", acknowledged)("w", waited));
sleep(1);
++waited;
}
if (waited == max) {
elog("http_connection::disconnect failed to receive all acks in time - sent ${s} | acked ${a} | waited ${w}",
elog("disconnect failed to receive all acks in time - sent ${s} | acked ${a} | waited ${w}",
("s", _sent.load())("a", _acknowledged.load())("w", waited));
}
if (_errors.load()) {
elog("${n} errors reported during http calls, see logs", ("n", _errors.load()));
}
}

bool http_connection::needs_response_trace_info() {
Expand Down Expand Up @@ -151,10 +156,17 @@ namespace eosio::testing {
trx_acknowledged(trx_id, fc::time_point::now());
if (ec) {
elog("http error: ${c}: ${m}", ("c", ec.value())("m", ec.message()));
throw std::runtime_error(ec.message());
++_errors;
return;
}

if (this->needs_response_trace_info() && response.result() == boost::beast::http::status::ok) {
bool exception = false;
auto exception_handler = [this, &response, &exception](const fc::exception_ptr& ex) {
elog("Fail to parse JSON from string: ${string}", ("string", response.body()));
++_errors;
exception = true;
};
try {
fc::variant resp_json = fc::json::from_string(response.body());
if (resp_json.is_object() && resp_json.get_object().contains("processed")) {
Expand Down Expand Up @@ -186,9 +198,9 @@ namespace eosio::testing {
elog("async_http_request Transaction failed, transaction not processed: ${string}",
("string", response.body()));
}
}
EOS_RETHROW_EXCEPTIONS(chain::json_parse_exception, "Fail to parse JSON from string: ${string}",
("string", response.body()));
} CATCH_AND_CALL(exception_handler)
if (exception)
return;
}

if (!(response.result() == boost::beast::http::status::accepted ||
Expand Down
1 change: 1 addition & 0 deletions tests/trx_generator/trx_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace eosio::testing {

std::atomic<uint64_t> _acknowledged{0};
std::atomic<uint64_t> _sent{0};
std::atomic<uint64_t> _errors{0};

explicit http_connection(const provider_base_config& provider_config)
: provider_connection(provider_config) {}
Expand Down

0 comments on commit 5bb7313

Please sign in to comment.