Skip to content

Commit fcd328c

Browse files
rubennortefacebook-github-bot
authored andcommitted
Add Fantom tests for scheduler yielding with idle callbacks
Summary: Extend the `requestIdleCallback` integration test suite with two cases that cover how idle callbacks interact with low priority tasks running through the scheduler: - `shouldYield` stays `false` while a low priority task is executing, even when an idle callback is scheduled in the middle of its execution (an idle callback is lower priority, so no yielding is warranted). - A low priority task scheduled after an idle callback executes before the idle callback, since the low priority task has a higher priority. Changelog: [Internal] Differential Revision: D110753031
1 parent e04ff69 commit fcd328c

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

packages/react-native/src/private/webapis/idlecallbacks/__tests__/requestIdleCallback-itest.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,54 @@ describe('requestIdleCallback', () => {
119119
requestIdleCallback(idleCallback);
120120
});
121121
});
122+
123+
it('should not yield while executing a low priority task even when scheduling an idle callback', () => {
124+
const {
125+
unstable_scheduleCallback,
126+
unstable_LowPriority,
127+
unstable_shouldYield,
128+
} = global.nativeRuntimeScheduler;
129+
130+
let shouldYieldBeforeSchedulingIdleCallback;
131+
let shouldYieldAfterSchedulingIdleCallback;
132+
133+
Fantom.runTask(() => {
134+
unstable_scheduleCallback(unstable_LowPriority, () => {
135+
shouldYieldBeforeSchedulingIdleCallback = unstable_shouldYield();
136+
137+
// Scheduling an idle callback (a lower priority task) must not turn
138+
// the currently executing low priority task into something that should
139+
// yield, as no higher priority work is pending.
140+
requestIdleCallback(() => {});
141+
142+
shouldYieldAfterSchedulingIdleCallback = unstable_shouldYield();
143+
});
144+
});
145+
146+
expect(shouldYieldBeforeSchedulingIdleCallback).toBe(false);
147+
expect(shouldYieldAfterSchedulingIdleCallback).toBe(false);
148+
});
149+
150+
it('should execute a low priority task scheduled after an idle callback before the idle callback', () => {
151+
const {unstable_scheduleCallback, unstable_LowPriority} =
152+
global.nativeRuntimeScheduler;
153+
154+
const executionOrder: Array<string> = [];
155+
156+
Fantom.runTask(() => {
157+
unstable_scheduleCallback(unstable_LowPriority, () => {
158+
// Even though the idle callback is scheduled first, the low priority
159+
// task scheduled after it has a higher priority, so it must run first.
160+
requestIdleCallback(() => {
161+
executionOrder.push('idleCallback');
162+
});
163+
164+
unstable_scheduleCallback(unstable_LowPriority, () => {
165+
executionOrder.push('lowPriorityTask');
166+
});
167+
});
168+
});
169+
170+
expect(executionOrder).toEqual(['lowPriorityTask', 'idleCallback']);
171+
});
122172
});

0 commit comments

Comments
 (0)