Skip to content

Commit

Permalink
Deflake LoopTest.WaitAnyBlocking and WaitAllBlocking. (iree-org#17863)
Browse files Browse the repository at this point in the history
Missed these in iree-org#17857 since I only
saw `WaitOneBlocking` flake on CI. The other test cases can flake too.
  • Loading branch information
ScottTodd committed Jul 11, 2024
1 parent b67fef7 commit c1611cd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions runtime/src/iree/base/loop_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ TEST_F(LoopTest, WaitOneBlocking) {
// Spin up the thread to signal the event after a short delay.
// We need to do this before we issue the wait so that loops which perform the
// wait inline can still make forward progress even if they block.
//
// Note: there is a race here that can cause flakes. If this new thread
// starts running after the iree_loop_wait_* timeout below, the status check
// will fail. We make the timeout there sufficiently long to give the OS
// enough time to switch threads a few times.
std::thread thread([&]() {
IREE_TRACE_SCOPE();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
Expand Down Expand Up @@ -768,6 +773,11 @@ TEST_F(LoopTest, WaitAnyBlocking) {
// Spin up the thread to signal the event after a short delay.
// We need to do this before we issue the wait so that loops which perform the
// wait inline can still make forward progress even if they block.
//
// Note: there is a race here that can cause flakes. If this new thread
// starts running after the iree_loop_wait_* timeout below, the status check
// will fail. We make the timeout there sufficiently long to give the OS
// enough time to switch threads a few times.
std::thread thread([&]() {
IREE_TRACE_SCOPE();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
Expand All @@ -783,7 +793,7 @@ TEST_F(LoopTest, WaitAnyBlocking) {
} user_data;
IREE_ASSERT_OK(iree_loop_wait_any(
loop, IREE_ARRAYSIZE(wait_sources), wait_sources,
iree_make_timeout_ms(200),
iree_make_timeout_ms(2000),
+[](void* user_data_ptr, iree_loop_t loop, iree_status_t status) {
IREE_TRACE_SCOPE();
IREE_EXPECT_OK(status);
Expand Down Expand Up @@ -941,6 +951,11 @@ TEST_F(LoopTest, WaitAllBlocking) {
// Spin up the thread to signal the event after a short delay.
// We need to do this before we issue the wait so that loops which perform the
// wait inline can still make forward progress even if they block.
//
// Note: there is a race here that can cause flakes. If this new thread
// starts running after the iree_loop_wait_* timeout below, the status check
// will fail. We make the timeout there sufficiently long to give the OS
// enough time to switch threads a few times.
std::thread thread([&]() {
IREE_TRACE_SCOPE();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
Expand All @@ -956,7 +971,7 @@ TEST_F(LoopTest, WaitAllBlocking) {
} user_data;
IREE_ASSERT_OK(iree_loop_wait_all(
loop, IREE_ARRAYSIZE(wait_sources), wait_sources,
iree_make_timeout_ms(200),
iree_make_timeout_ms(2000),
+[](void* user_data_ptr, iree_loop_t loop, iree_status_t status) {
IREE_TRACE_SCOPE();
IREE_EXPECT_OK(status);
Expand Down

0 comments on commit c1611cd

Please sign in to comment.