From f4972599013eb0b7b4a04bf8ac0dddb3f40c963f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 1 Aug 2025 07:54:28 -0700 Subject: [PATCH] Remove flakiness in LongTasksAPI test (#52974) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52974 Changelog: [internal] The test for LongTasks is flaky on Github and I made a change to figure out why (D79366370 / https://github.com/facebook/react-native/pull/52948). It seems that the long task happens before the artificial task we're using for testing, so we can update the test to filter those out. Reviewed By: cortinico Differential Revision: D79441987 fbshipit-source-id: 99296d704cfec2e61ca29d06878df171231f4e78 --- .../__tests__/LongTasksAPI-itest.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js index e9386cb6d10..80c8317318b 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js @@ -60,20 +60,20 @@ describe('LongTasks API', () => { observer.observe({entryTypes: ['longtask']}); }); - expect(callback).not.toHaveBeenCalled(); + const initialCallCount = callback.mock.calls.length; Fantom.runTask(() => { // Short task. }); - expect(callback).not.toHaveBeenCalled(); + expect(callback).toHaveBeenCalledTimes(initialCallCount); Fantom.runTask(() => { // Slightly longer task, but still not long. sleep(40); }); - expect(callback).not.toHaveBeenCalled(); + expect(callback).toHaveBeenCalledTimes(initialCallCount); }); it('reports long tasks (over 50ms)', () => { @@ -84,7 +84,7 @@ describe('LongTasks API', () => { observer.observe({entryTypes: ['longtask']}); }); - expect(callback).not.toHaveBeenCalled(); + const initialCallCount = callback.mock.calls.length; const beforeTaskStartTime = performance.now(); let afterTaskStartTime; @@ -97,7 +97,7 @@ describe('LongTasks API', () => { const afterTaskEndTime = performance.now(); - expect(callback).toHaveBeenCalledTimes(1); + expect(callback).toHaveBeenCalledTimes(initialCallCount + 1); const [entries, _observer, options] = callback.mock .lastCall as $FlowFixMe as [ @@ -135,7 +135,7 @@ describe('LongTasks API', () => { observer.observe({entryTypes: ['longtask']}); }); - expect(callback).not.toHaveBeenCalled(); + const initialCallCount = callback.mock.calls.length; const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield; @@ -147,7 +147,7 @@ describe('LongTasks API', () => { sleep(30); }); - expect(callback).not.toHaveBeenCalled(); + expect(callback).toHaveBeenCalledTimes(initialCallCount); }); it('should be reported if running for longer than 50ms between yielding opportunities', () => { @@ -158,7 +158,7 @@ describe('LongTasks API', () => { observer.observe({entryTypes: ['longtask']}); }); - expect(callback).not.toHaveBeenCalled(); + const initialCallCount = callback.mock.calls.length; const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield; @@ -176,7 +176,7 @@ describe('LongTasks API', () => { const afterTaskEndTime = performance.now(); - expect(callback).toHaveBeenCalledTimes(1); + expect(callback).toHaveBeenCalledTimes(initialCallCount + 1); const entries = callback.mock.lastCall[0] as PerformanceObserverEntryList; const allEntries = entries.getEntries();