Skip to content

Commit 384fc54

Browse files
rubennortefacebook-github-bot
authored andcommitted
Make observer go through Fanton.runTask in LongTasksAPI test (#52948)
Summary: Pull Request resolved: #52948 Changelog: [internal] Not sure why this test is flaky, but this tries to add some more assertions to see where the problem comes from. Reviewed By: hoxyq Differential Revision: D79366370 fbshipit-source-id: d66b30e502dbc80d3e972ed93a91bb7f703de9c4
1 parent 9d6d8a6 commit 384fc54

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ describe('LongTasks API', () => {
5555
it('does NOT report short tasks (under 50ms)', () => {
5656
const callback = jest.fn();
5757

58-
observer = new PerformanceObserver(callback);
59-
observer.observe({entryTypes: ['longtask']});
58+
Fantom.runTask(() => {
59+
observer = new PerformanceObserver(callback);
60+
observer.observe({entryTypes: ['longtask']});
61+
});
62+
63+
expect(callback).not.toHaveBeenCalled();
6064

6165
Fantom.runTask(() => {
6266
// Short task.
@@ -75,8 +79,12 @@ describe('LongTasks API', () => {
7579
it('reports long tasks (over 50ms)', () => {
7680
const callback = jest.fn();
7781

78-
observer = new PerformanceObserver(callback);
79-
observer.observe({entryTypes: ['longtask']});
82+
Fantom.runTask(() => {
83+
observer = new PerformanceObserver(callback);
84+
observer.observe({entryTypes: ['longtask']});
85+
});
86+
87+
expect(callback).not.toHaveBeenCalled();
8088

8189
const beforeTaskStartTime = performance.now();
8290
let afterTaskStartTime;
@@ -122,8 +130,12 @@ describe('LongTasks API', () => {
122130
it('should NOT be reported if they are longer than 50ms but had yielding opportunities in intervals shorter than 50ms', () => {
123131
const callback = jest.fn();
124132

125-
observer = new PerformanceObserver(callback);
126-
observer.observe({entryTypes: ['longtask']});
133+
Fantom.runTask(() => {
134+
observer = new PerformanceObserver(callback);
135+
observer.observe({entryTypes: ['longtask']});
136+
});
137+
138+
expect(callback).not.toHaveBeenCalled();
127139

128140
const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield;
129141

@@ -141,8 +153,12 @@ describe('LongTasks API', () => {
141153
it('should be reported if running for longer than 50ms between yielding opportunities', () => {
142154
const callback = jest.fn();
143155

144-
observer = new PerformanceObserver(callback);
145-
observer.observe({entryTypes: ['longtask']});
156+
Fantom.runTask(() => {
157+
observer = new PerformanceObserver(callback);
158+
observer.observe({entryTypes: ['longtask']});
159+
});
160+
161+
expect(callback).not.toHaveBeenCalled();
146162

147163
const shouldYield = global.nativeRuntimeScheduler.unstable_shouldYield;
148164

0 commit comments

Comments
 (0)