Skip to content

Commit

Permalink
connection: added unit test to showcase cleanup problem when waiting …
Browse files Browse the repository at this point in the history
…on never arriving messages
  • Loading branch information
ThomasDebrunner committed Feb 29, 2024
1 parent a9f8403 commit 3423d2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/mav/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ namespace mav {

public:

size_t callbackCount() {
std::scoped_lock<std::mutex> lock(_message_callback_mtx);
return _message_callbacks.size();
}

void removeAllCallbacks() {
std::scoped_lock<std::mutex> lock(_message_callback_mtx);
_message_callbacks.clear();
Expand Down
9 changes: 9 additions & 0 deletions tests/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,13 @@ TEST_CASE("Create network runtime") {
interface_partner));
CHECK(found);
}

SUBCASE("Callbacks are cleaned up on receive timeout") {
interface.reset();
for (int i = 0; i < 10; i++) {
auto expectation = connection->expect("TEST_MESSAGE");
CHECK_THROWS_AS(auto message = connection->receive(expectation, 100), TimeoutException);
}
CHECK_EQ(connection->callbackCount(), 0);
}
}

0 comments on commit 3423d2e

Please sign in to comment.