Skip to content

Commit 8cc9b32

Browse files
authored
fix(test): fix flaky WorkStealing.basic test with vcpu ready check (alibaba#1208)
Signed-off-by: huangzhaoxiang.hzx <huangzhaoxiang.hzx@alibaba-inc.com>
1 parent f9a83ad commit 8cc9b32

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

thread/test/test.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,21 +1841,28 @@ static void* ws_basic(void* arg) {
18411841
}
18421842

18431843
TEST(WorkStealing, basic) {
1844-
bool running = true, stolen = false;
1844+
bool running = true, ready = false, stolen = false;
18451845
std::thread vcpu([&](){
18461846
vcpu_init(VCPU_ENABLE_ACTIVE_WORK_STEALING);
1847-
while(running)
1847+
while(running) {
1848+
ready = true;
18481849
thread_usleep(1000);
1850+
}
18491851
DEFER(vcpu_fini());
18501852
});
1853+
while(!ready)
1854+
thread_usleep(1000);
18511855
auto th = thread_create(&ws_basic, &stolen, 0, 0,
18521856
THREAD_ENABLE_WORK_STEALING | THREAD_JOINABLE);
18531857
thread_pause_work_stealing(true, th);
18541858
::usleep(1000 * 10); // emulate a busy work of 10ms
18551859
EXPECT_FALSE(stolen);
18561860

18571861
thread_pause_work_stealing(false, th);
1858-
::usleep(1000 * 10); // emulate a busy work of 10ms
1862+
for (int i = 0; i < 100; i++) {
1863+
if (stolen) break;
1864+
::usleep(1000 * 10); // emulate a busy work of 10ms
1865+
}
18591866
EXPECT_TRUE(stolen);
18601867

18611868
thread_join((join_handle*)th);

0 commit comments

Comments
 (0)