Skip to content

Commit 195fd22

Browse files
authored
[tests] Fix flaky flight tests (facebook#35513)
Flights tests are failing locally and in CI non-deterministically because we're not disabling async hooks after tests, and GC can clear WeakRefs non-deterministically. This PR fixes the issue by adding an afterEach to disable installed hooks, and normalizing the `value` to `value: {value: undefined}}` when snapshotting.
1 parent d87298a commit 195fd22

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/internal-test-utils/debugInfo.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ function normalizeIOInfo(config: DebugInfoConfig, ioInfo) {
7979
status: promise.status,
8080
};
8181
}
82+
} else if ('value' in ioInfo) {
83+
// If value exists in ioInfo but is undefined (e.g., WeakRef was GC'd),
84+
// ensure we still include it in the normalized output for consistency
85+
copy.value = {
86+
value: undefined,
87+
};
88+
} else if (ioInfo.name && ioInfo.name !== 'rsc stream') {
89+
// For non-rsc-stream IO that doesn't have a value field, add a default.
90+
// This handles the case where the server doesn't send the field when WeakRef is GC'd.
91+
copy.value = {
92+
value: undefined,
93+
};
8294
}
8395
return copy;
8496
}

scripts/jest/setupTests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,14 @@ jest.mock('async_hooks', () => {
319319
},
320320
};
321321
});
322+
323+
// Ensure async hooks are disabled after each test to prevent cross-test pollution.
324+
// This is needed because test files that load the Node server (with async debug hooks)
325+
// can pollute test files that load the Edge server (which doesn't create new hooks
326+
// to trigger the cleanup in the mock above).
327+
afterEach(() => {
328+
if (installedHook) {
329+
installedHook.disable();
330+
installedHook = null;
331+
}
332+
});

0 commit comments

Comments
 (0)