Skip to content

Commit 938a338

Browse files
committed
Attempt to reduce flakyness on Modal-itest "MessageQueue is not empty" failure (#55486)
Summary: Pull Request resolved: #55486 The Modal integration test `<Modal> › ref › instance › uses the "RN:ModalHostView" tag name` was flaky on CI, intermittently failing with "MessageQueue is not empty" during the global afterEach `validateEmptyMessageQueue` hook. The root cause is that when Modal renders in __DEV__ mode, AppContainer's `useEffect` schedules passive effects as a deferred task on the RuntimeScheduler. Due to how microtask scheduling interacts with the RuntimeScheduler drain loop in Hermes, `flushMessageQueue()` inside `runTask` occasionally returns before this task is fully processed, leaving it on the queue for `validateEmptyMessageQueue` to find. The fix adds an `afterEach` hook at the top-level `describe('<Modal>')` block that calls `Fantom.runWorkLoop()`. This provides a second drain pass before the global `validateEmptyMessageQueue` check runs (inner afterEach hooks execute before outer ones). The call is a no-op when the queue is already empty, so it adds no overhead to tests where the initial drain was complete. This is consistent with patterns in Fantom-itest.js where Modal tests that call additional `runWorkLoop()` (for `enqueueModalSizeUpdate`) never exhibit this flakiness, precisely because that second drain catches any residual passive effects work. Changelog: [Internal] [Changed] - Reviewed By: rubennorte Differential Revision: D92828076 fbshipit-source-id: 529abe962044e2da6bee3b1e2ef4b129392fae06
1 parent 19582bf commit 938a338

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/react-native/Libraries/Modal/__tests__/Modal-itest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const DEFAULT_MODAL_CHILD_VIEW = (
2828
);
2929

3030
describe('<Modal>', () => {
31+
afterEach(() => {
32+
// Flush any remaining tasks that may have been scheduled during the
33+
// render (e.g. passive effects from AppContainer in __DEV__ mode).
34+
// This prevents flaky "MessageQueue is not empty" failures from the
35+
// global afterEach validation hook.
36+
Fantom.runWorkLoop();
37+
});
38+
3139
describe('props', () => {
3240
it('renders a Modal with the default values when no props are passed', () => {
3341
const root = Fantom.createRoot();

0 commit comments

Comments
 (0)