Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): flaky thread pool tests #2071

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading