Skip to content

Commit 3bff471

Browse files
rubennortefacebook-github-bot
authored andcommitted
Reduce flakiness of LongTasksAPI Fantom test (#52898)
Summary: Pull Request resolved: #52898 Changelog: [internal] This test is flaky on Github and I haven't been able to reproduce it locally to debug exactly why, but I think it might be because there might be cross-tests pollution. This tries to reduce that making sure we clean up everything between tests. Reviewed By: cortinico Differential Revision: D79163809 fbshipit-source-id: fe59315373ab74ccedd7e031816a84f0566b4aa0
1 parent dde4d34 commit 3bff471

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,22 @@ function ensurePerformanceLongTaskTiming(
4040
return value;
4141
}
4242

43+
let observer: ?PerformanceObserver;
44+
4345
describe('LongTasks API', () => {
46+
afterEach(() => {
47+
if (observer) {
48+
Fantom.runTask(() => {
49+
observer?.disconnect();
50+
observer = null;
51+
});
52+
}
53+
});
54+
4455
it('does NOT report short tasks (under 50ms)', () => {
4556
const callback = jest.fn();
4657

47-
const observer = new PerformanceObserver(callback);
58+
observer = new PerformanceObserver(callback);
4859
observer.observe({entryTypes: ['longtask']});
4960

5061
Fantom.runTask(() => {
@@ -64,7 +75,7 @@ describe('LongTasks API', () => {
6475
it('reports long tasks (over 50ms)', () => {
6576
const callback = jest.fn();
6677

67-
const observer = new PerformanceObserver(callback);
78+
observer = new PerformanceObserver(callback);
6879
observer.observe({entryTypes: ['longtask']});
6980

7081
const beforeTaskStartTime = performance.now();
@@ -111,17 +122,17 @@ describe('LongTasks API', () => {
111122
it('should NOT be reported if they are longer than 50ms but had yielding opportunities in intervals shorter than 50ms', () => {
112123
const callback = jest.fn();
113124

114-
const observer = new PerformanceObserver(callback);
125+
observer = new PerformanceObserver(callback);
115126
observer.observe({entryTypes: ['longtask']});
116127

117128
const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield;
118129

119130
Fantom.runTask(() => {
120-
sleep(40);
131+
sleep(30);
121132
shouldYield();
122-
sleep(40);
133+
sleep(30);
123134
shouldYield();
124-
sleep(40);
135+
sleep(30);
125136
});
126137

127138
expect(callback).not.toHaveBeenCalled();
@@ -130,7 +141,7 @@ describe('LongTasks API', () => {
130141
it('should be reported if running for longer than 50ms between yielding opportunities', () => {
131142
const callback = jest.fn();
132143

133-
const observer = new PerformanceObserver(callback);
144+
observer = new PerformanceObserver(callback);
134145
observer.observe({entryTypes: ['longtask']});
135146

136147
const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield;

0 commit comments

Comments
 (0)