Skip to content

Commit

Permalink
fix(tests): flaky thread pool tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gianmatteo Palmieri <[email protected]>
  • Loading branch information
mrgian authored and poiana committed Oct 9, 2024
1 parent cfd262e commit 6a586d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions userspace/libsinsp/test/plugins.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,15 +1092,15 @@ TEST_F(sinsp_with_test_input, plugin_routines) {
PPM_O_RDWR,
0);
std::this_thread::sleep_for(
std::chrono::nanoseconds(1000)); // wait for a bit to let routine finish
std::chrono::milliseconds(100)); // wait for a bit to let routine finish
routines_num = tp->routines_num();
ASSERT_EQ(routines_num, 1);

// step: #5: the plugin doesn't unsubscribe the last routine, but the thread pool shuould
// unsubscribe it on capture close
m_inspector.close();
std::this_thread::sleep_for(
std::chrono::nanoseconds(100)); // wait for a bit to let routine finish
std::chrono::milliseconds(100)); // wait for a bit to let routine finish
routines_num = tp->routines_num();
ASSERT_EQ(routines_num, 0);
}
Expand Down
9 changes: 5 additions & 4 deletions userspace/libsinsp/test/thread_pool.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ TEST_F(sinsp_with_test_input, thread_pool) {
std::atomic<int> count = 0;
std::atomic<bool> routine_exited = false;
r = tp->subscribe([&count, &routine_exited] {
if(count >= 1024) {
if(count >= 10) {
routine_exited = true;
return false;
}
count++;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return true;
});
ASSERT_EQ(tp->routines_num(), 1);

// the routine above keeps increasing a counter, until the counter reaches 1024
// the routine above keeps increasing a counter, until the counter reaches 10
// we wait for the routine to exit, then we check if it has been unsubscribed
while(!routine_exited) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
ASSERT_EQ(count, 1024);
ASSERT_EQ(count, 10);
ASSERT_EQ(tp->routines_num(), 0);

// all the remaining routines should be unsubscribed when the inspector is closed
Expand Down

0 comments on commit 6a586d7

Please sign in to comment.