Skip to content

Commit dd5c6d7

Browse files
Make the stranded-synchronous-request test deterministic
The driver ticked the queue exactly twice, but the number of queued tasks depends on thread interleaving: when the synchronous access request is queued before the first tick, the scheduled beat's work item yields without executing and is re-queued for a third tick that never came. Drive the queue from the test thread with the same waitForTasks synchronization the RuntimeScheduler tests use, asserting each stage.
1 parent ebee670 commit dd5c6d7

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

  • packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests

‎packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests/EventBeatTest.cpp‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,26 @@ TEST_F(EventBeatTest, synchronousRequestIsNotStrandedBehindScheduledBeat) {
153153
// A synchronous request arriving now must still be processed by its induce
154154
// instead of being silently deferred behind the scheduled beat.
155155
eventBeat_->requestSynchronous();
156-
std::thread driver([this]() {
157-
stubQueue_->waitForTask();
158-
stubQueue_->tick();
159-
stubQueue_->waitForTask();
160-
stubQueue_->tick();
161-
});
162-
eventBeat_->induce();
163-
driver.join();
156+
std::thread inducer([this]() { eventBeat_->induce(); });
157+
158+
// Wait until the synchronous access request joins the already-queued work
159+
// item, so that the tick order below is deterministic.
160+
stubQueue_->waitForTasks(2);
161+
162+
// The scheduled beat's work item yields to the pending synchronous access
163+
// without executing.
164+
stubQueue_->tick();
165+
EXPECT_EQ(beatCount, 0);
164166

167+
// The synchronous access processes the beat within its induce.
168+
stubQueue_->tick();
169+
inducer.join();
170+
EXPECT_EQ(beatCount, 1);
171+
172+
// The beat that yielded resumes afterwards; it was not lost.
173+
stubQueue_->tick();
165174
EXPECT_EQ(beatCount, 2);
175+
EXPECT_EQ(stubQueue_->size(), 0);
166176
}
167177

168178
} // namespace facebook::react

0 commit comments

Comments
 (0)