mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	chore: align monotonicTime across processes (#35130)
This commit is contained in:
		
							parent
							
								
									43ee924087
								
							
						
					
					
						commit
						ec4c66133e
					
				@ -14,6 +14,18 @@
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
export function monotonicTime(): number {
 | 
			
		||||
  return Math.floor(performance.now() * 1000) / 1000;
 | 
			
		||||
let _timeOrigin = performance.timeOrigin;
 | 
			
		||||
let _timeShift = 0;
 | 
			
		||||
 | 
			
		||||
export function setTimeOrigin(origin: number) {
 | 
			
		||||
  _timeOrigin = origin;
 | 
			
		||||
  _timeShift = performance.timeOrigin - origin;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function timeOrigin(): number {
 | 
			
		||||
  return _timeOrigin;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function monotonicTime(): number {
 | 
			
		||||
  return Math.floor((performance.now() + _timeShift) * 1000) / 1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -55,6 +55,7 @@ export type SerializedConfig = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export type ProcessInitParams = {
 | 
			
		||||
  timeOrigin: number;
 | 
			
		||||
  processName: string;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { startProfiling, stopProfiling } from 'playwright-core/lib/utils';
 | 
			
		||||
import { setTimeOrigin, startProfiling, stopProfiling } from 'playwright-core/lib/utils';
 | 
			
		||||
 | 
			
		||||
import { serializeError } from '../util';
 | 
			
		||||
import { registerESMLoader } from './esmLoaderHost';
 | 
			
		||||
@ -69,6 +69,7 @@ process.on('message', async (message: any) => {
 | 
			
		||||
  if (message.method === '__init__') {
 | 
			
		||||
    const { processParams, runnerParams, runnerScript } = message.params as { processParams: ProcessInitParams, runnerParams: any, runnerScript: string };
 | 
			
		||||
    void startProfiling();
 | 
			
		||||
    setTimeOrigin(processParams.timeOrigin);
 | 
			
		||||
    const { create } = require(runnerScript);
 | 
			
		||||
    processRunner = create(runnerParams) as ProcessRunner;
 | 
			
		||||
    processName = processParams.processName;
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@
 | 
			
		||||
import child_process from 'child_process';
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
 | 
			
		||||
import { assert } from 'playwright-core/lib/utils';
 | 
			
		||||
import { assert, timeOrigin } from 'playwright-core/lib/utils';
 | 
			
		||||
import { debug } from 'playwright-core/lib/utilsBundle';
 | 
			
		||||
 | 
			
		||||
import { esmLoaderRegistered } from '../common/esmLoaderHost';
 | 
			
		||||
@ -115,7 +115,8 @@ export class ProcessHost extends EventEmitter {
 | 
			
		||||
      return error;
 | 
			
		||||
 | 
			
		||||
    const processParams: ProcessInitParams = {
 | 
			
		||||
      processName: this._processName
 | 
			
		||||
      processName: this._processName,
 | 
			
		||||
      timeOrigin: timeOrigin(),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    this.send({
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user