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 <mail@gian.im>
  • Loading branch information
mrgian committed Sep 16, 2024
1 parent 5919fa9 commit e69d1a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/plugins.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ 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::nanoseconds(2000)); // wait for a bit to let routine finish
routines_num = tp->routines_num();
ASSERT_EQ(routines_num, 1);

Expand Down
8 changes: 4 additions & 4 deletions userspace/libsinsp/test/thread_pool.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ 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 >= 2048) {
routine_exited = true;
return false;
}
Expand All @@ -57,12 +57,12 @@ TEST_F(sinsp_with_test_input, thread_pool) {
});
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 2048
// 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, 2048);
ASSERT_EQ(tp->routines_num(), 0);

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

0 comments on commit e69d1a1

Please sign in to comment.