chore: fix simulated clock bots (#31301)

This commit is contained in:
Pavel Feldman 2024-06-17 09:17:38 -07:00 committed by GitHub
parent b62af828c3
commit 2a7f17d820
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 37 additions and 21 deletions

View File

@ -88,11 +88,15 @@ jobs:
flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }} flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }}
test_clock_frozen_time_linux: test_clock_frozen_time_linux:
name: Frozen time library name: time library - ${{ matrix.clock }}
environment: ${{ github.event_name == 'push' && 'allow-uploading-flakiness-results' || null }} environment: ${{ github.event_name == 'push' && 'allow-uploading-flakiness-results' || null }}
permissions: permissions:
id-token: write # This is required for OIDC login (azure/login) to succeed id-token: write # This is required for OIDC login (azure/login) to succeed
contents: read # This is required for actions/checkout to succeed contents: read # This is required for actions/checkout to succeed
strategy:
fail-fast: false
matrix:
clock: [frozen, realtime]
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -101,32 +105,36 @@ jobs:
node-version: 20 node-version: 20
browsers-to-install: chromium browsers-to-install: chromium
command: npm run test -- --project=chromium-* command: npm run test -- --project=chromium-*
bot-name: "frozen-time-library-chromium-linux" bot-name: "${{ matrix.clock }}-time-library-chromium-linux"
flakiness-client-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_CLIENT_ID }} flakiness-client-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_CLIENT_ID }}
flakiness-tenant-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_TENANT_ID }} flakiness-tenant-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_TENANT_ID }}
flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }} flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }}
env: env:
PW_FREEZE_TIME: 1 PW_CLOCK: ${{ matrix.clock }}
test_clock_frozen_time_test_runner: test_clock_frozen_time_test_runner:
name: Frozen time test runner name: time test runner - ${{ matrix.clock }}
environment: ${{ github.event_name == 'push' && 'allow-uploading-flakiness-results' || null }} environment: ${{ github.event_name == 'push' && 'allow-uploading-flakiness-results' || null }}
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
permissions: permissions:
id-token: write # This is required for OIDC login (azure/login) to succeed id-token: write # This is required for OIDC login (azure/login) to succeed
contents: read # This is required for actions/checkout to succeed contents: read # This is required for actions/checkout to succeed
strategy:
fail-fast: false
matrix:
clock: [frozen, realtime]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./.github/actions/run-test - uses: ./.github/actions/run-test
with: with:
node-version: 20 node-version: 20
command: npm run ttest command: npm run ttest
bot-name: "frozen-time-runner-chromium-linux" bot-name: "${{ matrix.clock }}-time-runner-chromium-linux"
flakiness-client-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_CLIENT_ID }} flakiness-client-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_CLIENT_ID }}
flakiness-tenant-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_TENANT_ID }} flakiness-tenant-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_TENANT_ID }}
flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }} flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }}
env: env:
PW_FREEZE_TIME: 1 PW_CLOCK: ${{ matrix.clock }}
test_electron: test_electron:
name: Electron - ${{ matrix.os }} name: Electron - ${{ matrix.os }}

View File

@ -85,11 +85,15 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
const response = forReuse ? await this._channel.newContextForReuse(contextOptions) : await this._channel.newContext(contextOptions); const response = forReuse ? await this._channel.newContextForReuse(contextOptions) : await this._channel.newContext(contextOptions);
const context = BrowserContext.from(response.context); const context = BrowserContext.from(response.context);
await this._browserType._didCreateContext(context, contextOptions, this._options, options.logger || this._logger); await this._browserType._didCreateContext(context, contextOptions, this._options, options.logger || this._logger);
if (!forReuse && !!process.env.PW_FREEZE_TIME) { if (!forReuse && process.env.PW_CLOCK === 'frozen') {
await this._wrapApiCall(async () => { await this._wrapApiCall(async () => {
await context.clock.install({ time: 0 }); await context.clock.install({ time: 0 });
await context.clock.pauseAt(1000); await context.clock.pauseAt(1000);
}, true); }, true);
} else if (!forReuse && process.env.PW_CLOCK === 'realtime') {
await this._wrapApiCall(async () => {
await context.clock.install({ time: 0 });
}, true);
} }
return context; return context;
} }

View File

@ -705,11 +705,12 @@ export function install(globalObject: WindowOrWorkerGlobalScope, config: Install
} }
export function inject(globalObject: WindowOrWorkerGlobalScope) { export function inject(globalObject: WindowOrWorkerGlobalScope) {
const builtin = platformOriginals(globalObject).bound;
const { clock: controller } = install(globalObject); const { clock: controller } = install(globalObject);
controller.resume(); controller.resume();
return { return {
controller, controller,
builtin: platformOriginals(globalObject).bound, builtin,
}; };
} }

View File

@ -391,7 +391,7 @@ it('should(not) block third party cookies', async ({ context, page, server, brow
it('should not block third party SameSite=None cookies', async ({ contextFactory, httpsServer, browserName }) => { it('should not block third party SameSite=None cookies', async ({ contextFactory, httpsServer, browserName }) => {
it.skip(browserName === 'webkit', 'No third party cookies in WebKit'); it.skip(browserName === 'webkit', 'No third party cookies in WebKit');
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(process.env.PW_CLOCK === 'frozen');
const context = await contextFactory({ const context = await contextFactory({
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
}); });

View File

@ -43,7 +43,7 @@ it('should ignore eval() scripts by default', async function({ page, server }) {
}); });
it('shouldn\'t ignore eval() scripts if reportAnonymousScripts is true', async function({ page, server }) { it('shouldn\'t ignore eval() scripts if reportAnonymousScripts is true', async function({ page, server }) {
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(!!process.env.PW_CLOCK);
await page.coverage.startJSCoverage({ reportAnonymousScripts: true }); await page.coverage.startJSCoverage({ reportAnonymousScripts: true });
await page.goto(server.PREFIX + '/jscoverage/eval.html'); await page.goto(server.PREFIX + '/jscoverage/eval.html');
const coverage = await page.coverage.stopJSCoverage(); const coverage = await page.coverage.stopJSCoverage();

View File

@ -156,7 +156,7 @@ it('should(not) block third party cookies', async ({ page, server, allowsThirdPa
it('should not block third party SameSite=None cookies', async ({ httpsServer, browserName, browser }) => { it('should not block third party SameSite=None cookies', async ({ httpsServer, browserName, browser }) => {
it.skip(browserName === 'webkit', 'No third party cookies in WebKit'); it.skip(browserName === 'webkit', 'No third party cookies in WebKit');
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(process.env.PW_CLOCK === 'frozen');
const page = await browser.newPage({ const page = await browser.newPage({
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
}); });

View File

@ -16,9 +16,12 @@
import { test as it, expect } from './pageTest'; import { test as it, expect } from './pageTest';
it.skip(!process.env.PW_FREEZE_TIME);
it('clock should be frozen', async ({ page }) => { it('clock should be frozen', async ({ page }) => {
await page.clock.setSystemTime(0); it.skip(process.env.PW_CLOCK !== 'frozen');
expect(await page.evaluate('Date.now()')).toBe(0); expect(await page.evaluate('Date.now()')).toBe(1000);
});
it('clock should be realtime', async ({ page }) => {
it.skip(process.env.PW_CLOCK !== 'realtime');
expect(await page.evaluate('Date.now()')).toBeLessThan(1000);
}); });

View File

@ -16,7 +16,7 @@
import { test, expect } from './pageTest'; import { test, expect } from './pageTest';
test.skip(!!process.env.PW_FREEZE_TIME); test.skip(!!process.env.PW_CLOCK);
declare global { declare global {
interface Window { interface Window {

View File

@ -362,7 +362,7 @@ it('should properly serialize PerformanceMeasure object', async ({ page }) => {
}); });
it('should properly serialize window.performance object', async ({ page }) => { it('should properly serialize window.performance object', async ({ page }) => {
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(!!process.env.PW_CLOCK);
expect(await page.evaluate(() => performance)).toEqual({ expect(await page.evaluate(() => performance)).toEqual({
'navigation': { 'navigation': {

View File

@ -481,7 +481,7 @@ it('js redirect overrides url bar navigation ', async ({ page, server, browserNa
it('should succeed on url bar navigation when there is pending navigation', async ({ page, server, browserName }) => { it('should succeed on url bar navigation when there is pending navigation', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21574' }); it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21574' });
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(process.env.PW_CLOCK === 'frozen');
server.setRoute('/a', (req, res) => { server.setRoute('/a', (req, res) => {
res.writeHead(200, { 'content-type': 'text/html' }); res.writeHead(200, { 'content-type': 'text/html' });
res.end(` res.end(`
@ -754,7 +754,7 @@ it('should properly wait for load', async ({ page, server, browserName }) => {
it('should not resolve goto upon window.stop()', async ({ browserName, page, server }) => { it('should not resolve goto upon window.stop()', async ({ browserName, page, server }) => {
it.fixme(browserName === 'firefox', 'load/domcontentloaded events are flaky'); it.fixme(browserName === 'firefox', 'load/domcontentloaded events are flaky');
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(process.env.PW_CLOCK === 'frozen');
let response; let response;
server.setRoute('/module.js', (req, res) => { server.setRoute('/module.js', (req, res) => {
@ -797,7 +797,7 @@ it('should return when navigation is committed if commit is specified', async ({
}); });
it('should wait for load when iframe attaches and detaches', async ({ page, server }) => { it('should wait for load when iframe attaches and detaches', async ({ page, server }) => {
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(process.env.PW_CLOCK === 'frozen');
server.setRoute('/empty.html', (req, res) => { server.setRoute('/empty.html', (req, res) => {
res.writeHead(200, { 'content-type': 'text/html' }); res.writeHead(200, { 'content-type': 'text/html' });
res.end(` res.end(`

View File

@ -245,7 +245,7 @@ it('page.goForward during renderer-initiated navigation', async ({ page, server
it('regression test for issue 20791', async ({ page, server }) => { it('regression test for issue 20791', async ({ page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/20791' }); it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/20791' });
it.skip(!!process.env.PW_FREEZE_TIME); it.skip(process.env.PW_CLOCK === 'frozen');
server.setRoute('/iframe.html', (req, res) => { server.setRoute('/iframe.html', (req, res) => {
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }); res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
// iframe access parent frame to log a value from it. // iframe access parent frame to log a value from it.