Skip to content

Commit ec4c661

Browse files
authored
chore: align monotonicTime across processes (#35130)
1 parent 43ee924 commit ec4c661

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

packages/playwright-core/src/utils/isomorphic/time.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17+
let _timeOrigin = performance.timeOrigin;
18+
let _timeShift = 0;
19+
20+
export function setTimeOrigin(origin: number) {
21+
_timeOrigin = origin;
22+
_timeShift = performance.timeOrigin - origin;
23+
}
24+
25+
export function timeOrigin(): number {
26+
return _timeOrigin;
27+
}
28+
1729
export function monotonicTime(): number {
18-
return Math.floor(performance.now() * 1000) / 1000;
30+
return Math.floor((performance.now() + _timeShift) * 1000) / 1000;
1931
}

packages/playwright/src/common/ipc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type SerializedConfig = {
5555
};
5656

5757
export type ProcessInitParams = {
58+
timeOrigin: number;
5859
processName: string;
5960
};
6061

packages/playwright/src/common/process.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { startProfiling, stopProfiling } from 'playwright-core/lib/utils';
17+
import { setTimeOrigin, startProfiling, stopProfiling } from 'playwright-core/lib/utils';
1818

1919
import { serializeError } from '../util';
2020
import { registerESMLoader } from './esmLoaderHost';
@@ -69,6 +69,7 @@ process.on('message', async (message: any) => {
6969
if (message.method === '__init__') {
7070
const { processParams, runnerParams, runnerScript } = message.params as { processParams: ProcessInitParams, runnerParams: any, runnerScript: string };
7171
void startProfiling();
72+
setTimeOrigin(processParams.timeOrigin);
7273
const { create } = require(runnerScript);
7374
processRunner = create(runnerParams) as ProcessRunner;
7475
processName = processParams.processName;

packages/playwright/src/runner/processHost.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import child_process from 'child_process';
1818
import { EventEmitter } from 'events';
1919

20-
import { assert } from 'playwright-core/lib/utils';
20+
import { assert, timeOrigin } from 'playwright-core/lib/utils';
2121
import { debug } from 'playwright-core/lib/utilsBundle';
2222

2323
import { esmLoaderRegistered } from '../common/esmLoaderHost';
@@ -115,7 +115,8 @@ export class ProcessHost extends EventEmitter {
115115
return error;
116116

117117
const processParams: ProcessInitParams = {
118-
processName: this._processName
118+
processName: this._processName,
119+
timeOrigin: timeOrigin(),
119120
};
120121

121122
this.send({

0 commit comments

Comments
 (0)