Skip to content

Commit a8a5c5e

Browse files
rubennortefacebook-github-bot
authored andcommitted
Skip Performance timeOrigin test on macOS hosts
Summary: The `timeOrigin` test in `Performance-itest` compares `performance.now() + performance.timeOrigin` against `Date.now()`. On macOS this comparison is unreliable because `performance.now()` is backed by a monotonic clock that does NOT advance while the system is asleep, so the monotonic time drifts relative to wall time the longer the machine has been running. Use the new `Fantom.getHostPlatform()` to skip just this test on macOS hosts while keeping it active on other platforms. A comment explains why the test cannot be run there. Also adds a small test verifying that `performance.timeOrigin` is a positive number and is stable across calls. Changelog: [Internal] Reviewed By: javache Differential Revision: D106669674
1 parent 1f994b3 commit a8a5c5e

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

13+
import * as Fantom from '@react-native/fantom';
14+
1315
describe('Performance', () => {
1416
it('does NOT allow creating instances of Performance directly', () => {
1517
expect(() => {
@@ -40,7 +42,24 @@ describe('Performance', () => {
4042
});
4143

4244
describe('timeOrigin', () => {
43-
it('allows moving timestamps to Unix epoch', () => {
45+
it('is a positive number that does not change between calls', () => {
46+
const first = performance.timeOrigin;
47+
const second = performance.timeOrigin;
48+
49+
expect(typeof first).toBe('number');
50+
expect(first).toBeGreaterThan(0);
51+
expect(second).toBe(first);
52+
});
53+
54+
// On macOS, `performance.now()` is backed by a monotonic clock that does
55+
// NOT include time spent while the system is asleep. This causes the
56+
// monotonic time to drift relative to wall time (`Date.now()`) the longer
57+
// the machine has been running, so we can't reliably compare
58+
// `performance.now() + performance.timeOrigin` against `Date.now()` like
59+
// we can on other platforms.
60+
const itIfNotMacOS = Fantom.getHostPlatform() === 'macos' ? it.skip : it;
61+
62+
itIfNotMacOS('allows moving timestamps to Unix epoch', () => {
4463
// We need to truncate timestamps because `Date.now()` only provides
4564
// integer millisecond precision.
4665
const adjustedMonotonicTime = Math.trunc(

0 commit comments

Comments
 (0)