AppLayerLabs / bdk-cpp

MIT License
7 stars 12 forks source link

Add optional TEST_CHECK_TIME macro for tests #112

Closed fcecin closed 3 months ago

fcecin commented 3 months ago

This adds a TEST_CHECK_TIME (and a TEST_CHECK_TIME_VERBOSE) macro that can be used inside the REQURE() macro in tests.

These allow us to decouple a test correctness timeout (say, 3 minutes) from a soft test duration check.

Example: (in state.cpp)

REQUIRE(TEST_CHECK_TIME(confirmFuture.wait_for(std::chrono::seconds(120)) != std::future_status::timeout, 5));

This will fail the test if it takes more than 2 minutes to complete. However, if it takes more than 5 seconds to complete, it will print a warning. This allows us to keep an eye on test durations that may (or may not) accuse bugs or other problems we may want to fix or improve, without confusing those with correctness bugs.

Here's what it looks like when the assert fails; it is a bit uglier, but still understandable:

/home/fcecin/applayer/development/bdk-cpp/tests/core/state.cpp:1166: FAILED:
  REQUIRE( testCheckTime("/home/fcecin/applayer/development/bdk-cpp/tests/core/state.cpp", 1166, [&]() { return (confirmFuture.wait_for(std::chrono::seconds(1)) != std::future_status::timeout); }, 5, false) )
with expansion:
  false
bdk-cpp-sonarqube-app[bot] commented 3 months ago

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube