From 1aeee082ae0cdf414dea2a5a12a76ad6923d25b8 Mon Sep 17 00:00:00 2001 From: EricLiu2000 Date: Mon, 5 Aug 2019 11:40:47 -0400 Subject: [PATCH] Testing successful removal of events from within event callbacks --- test/eventmanagertest.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/eventmanagertest.cpp b/test/eventmanagertest.cpp index 7adb634..2de8237 100644 --- a/test/eventmanagertest.cpp +++ b/test/eventmanagertest.cpp @@ -16,8 +16,9 @@ protected: }; /** - * Tests behavior of adding event callbcaks on multiple threads. + * Tests behavior of adding event callbacks on multiple threads. * The order in which they are called is not guaranteed, but we check for the correct amount of calls. + * Each callback also flushes the event buffer upon call. */ TEST_F(EventManagerTest, MultithreadedEventCallbacksTest) { int callCounter = 0; @@ -28,6 +29,7 @@ TEST_F(EventManagerTest, MultithreadedEventCallbacksTest) { int id1 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter, &mutex](std::shared_ptr){ std::lock_guard lk(mutex); callCounter++; + EventManager::GetInstance().get(); }, EventFilter(APIEvent::Type::BaudrateNotFound))); // shouldn't add anything @@ -45,6 +47,7 @@ TEST_F(EventManagerTest, MultithreadedEventCallbacksTest) { int id2 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter, &mutex](std::shared_ptr) { std::lock_guard lk(mutex); callCounter++; + EventManager::GetInstance().get(); }, EventFilter(APIEvent::Severity::EventInfo))); // shouldn't add anything @@ -59,10 +62,14 @@ TEST_F(EventManagerTest, MultithreadedEventCallbacksTest) { t1.join(); t2.join(); + EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(callCounter, 2); EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); + EXPECT_EQ(EventCount(), 1); + EXPECT_EQ(callCounter, 2); }