Skip to content

Commit

Permalink
Resolve race condition in test suite
Browse files Browse the repository at this point in the history
There can be a spurious failure here if the backdoor_details element
hasn't been added yet, so lock & check it when waiting for the test
conditions.

The weirdest thing about this error is that it can fail but then when
expanding values they expand to *correct* values, i.e. so you get:

FAILED:
  REQUIRE( backdoor_details == all_the_things )
with expansion:
  { "Alaska", "I'm the luckiest man in the world", "Loretta", "because all my
  life are belong to Google", "moustache hatred", "photos", "scallops",
  "snorted when she laughed", "tickled pink" }
  ==
  { "Alaska", "I'm the luckiest man in the world", "Loretta", "because all my
  life are belong to Google", "moustache hatred", "photos", "scallops",
  "snorted when she laughed", "tickled pink" }
  • Loading branch information
jagerman committed Jun 8, 2020
1 parent 3edcab9 commit 278909d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/test_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ TEST_CASE("deferred replies on incoming connections", "[commands][hey google]")
LokiMQ nsa{get_logger("NSA» ")};
nsa.add_category("backdoor", Access{AuthLevel::admin});
nsa.add_command("backdoor", "data", [&](Message& m) {
backdoor_details.emplace(m.data[0]);
auto l = catch_lock();
backdoor_details.emplace(m.data[0]);
});
nsa.start();
auto nsa_c = nsa.connect_remote(listen, connect_success, connect_failure, server.get_pubkey(), AuthLevel::admin);
Expand Down Expand Up @@ -252,7 +253,7 @@ TEST_CASE("deferred replies on incoming connections", "[commands][hey google]")
},
personal_detail);
}
wait_for([&] { auto lock = catch_lock(); return things_remembered == all_the_things.size(); });
wait_for([&] { auto lock = catch_lock(); return things_remembered == all_the_things.size() && things_remembered == backdoor_details.size(); });
{
auto l = catch_lock();
REQUIRE( things_remembered == all_the_things.size() );
Expand Down

0 comments on commit 278909d

Please sign in to comment.