Skip to content

Commit f497259

Browse files
rubennortefacebook-github-bot
authored andcommitted
Remove flakiness in LongTasksAPI test (#52974)
Summary: Pull Request resolved: #52974 Changelog: [internal] The test for LongTasks is flaky on Github and I made a change to figure out why (D79366370 / #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
1 parent c43a399 commit f497259

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ describe('LongTasks API', () => {
6060
observer.observe({entryTypes: ['longtask']});
6161
});
6262

63-
expect(callback).not.toHaveBeenCalled();
63+
const initialCallCount = callback.mock.calls.length;
6464

6565
Fantom.runTask(() => {
6666
// Short task.
6767
});
6868

69-
expect(callback).not.toHaveBeenCalled();
69+
expect(callback).toHaveBeenCalledTimes(initialCallCount);
7070

7171
Fantom.runTask(() => {
7272
// Slightly longer task, but still not long.
7373
sleep(40);
7474
});
7575

76-
expect(callback).not.toHaveBeenCalled();
76+
expect(callback).toHaveBeenCalledTimes(initialCallCount);
7777
});
7878

7979
it('reports long tasks (over 50ms)', () => {
@@ -84,7 +84,7 @@ describe('LongTasks API', () => {
8484
observer.observe({entryTypes: ['longtask']});
8585
});
8686

87-
expect(callback).not.toHaveBeenCalled();
87+
const initialCallCount = callback.mock.calls.length;
8888

8989
const beforeTaskStartTime = performance.now();
9090
let afterTaskStartTime;
@@ -97,7 +97,7 @@ describe('LongTasks API', () => {
9797

9898
const afterTaskEndTime = performance.now();
9999

100-
expect(callback).toHaveBeenCalledTimes(1);
100+
expect(callback).toHaveBeenCalledTimes(initialCallCount + 1);
101101

102102
const [entries, _observer, options] = callback.mock
103103
.lastCall as $FlowFixMe as [
@@ -135,7 +135,7 @@ describe('LongTasks API', () => {
135135
observer.observe({entryTypes: ['longtask']});
136136
});
137137

138-
expect(callback).not.toHaveBeenCalled();
138+
const initialCallCount = callback.mock.calls.length;
139139

140140
const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield;
141141

@@ -147,7 +147,7 @@ describe('LongTasks API', () => {
147147
sleep(30);
148148
});
149149

150-
expect(callback).not.toHaveBeenCalled();
150+
expect(callback).toHaveBeenCalledTimes(initialCallCount);
151151
});
152152

153153
it('should be reported if running for longer than 50ms between yielding opportunities', () => {
@@ -158,7 +158,7 @@ describe('LongTasks API', () => {
158158
observer.observe({entryTypes: ['longtask']});
159159
});
160160

161-
expect(callback).not.toHaveBeenCalled();
161+
const initialCallCount = callback.mock.calls.length;
162162

163163
const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield;
164164

@@ -176,7 +176,7 @@ describe('LongTasks API', () => {
176176

177177
const afterTaskEndTime = performance.now();
178178

179-
expect(callback).toHaveBeenCalledTimes(1);
179+
expect(callback).toHaveBeenCalledTimes(initialCallCount + 1);
180180

181181
const entries = callback.mock.lastCall[0] as PerformanceObserverEntryList;
182182
const allEntries = entries.getEntries();

0 commit comments

Comments
 (0)