From a35d2070914893719c28975c31da6cc375ea9e76 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 13 Nov 2020 14:10:32 -0800 Subject: [PATCH] test: fix resource timing for bigsur test (#4419) --- src/server/webkit/wkInterceptableRequest.ts | 4 +- test/resource-timing.spec.ts | 61 +++++++-------------- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/src/server/webkit/wkInterceptableRequest.ts b/src/server/webkit/wkInterceptableRequest.ts index a05a993952..0c4095dbf8 100644 --- a/src/server/webkit/wkInterceptableRequest.ts +++ b/src/server/webkit/wkInterceptableRequest.ts @@ -132,9 +132,9 @@ function wkMillisToRoundishMillis(value: number): number { return -1; // WebKit has a bug, instead of -1 it sends -1000 to be in ms. - if (value < 0) { + if (value <= 0) { // DNS can start before request start on Mac Network Stack - return 0; + return -1; } return ((value * 1000) | 0) / 1000; diff --git a/test/resource-timing.spec.ts b/test/resource-timing.spec.ts index ae635b24cb..47f7296cf5 100644 --- a/test/resource-timing.spec.ts +++ b/test/resource-timing.spec.ts @@ -23,58 +23,35 @@ it('should work', async ({ page, server }) => { page.goto(server.EMPTY_PAGE) ]); const timing = request.timing(); - expect(timing.domainLookupStart).toBeGreaterThanOrEqual(0); - expect(timing.domainLookupEnd).toBeGreaterThanOrEqual(timing.domainLookupStart); - expect(timing.connectStart).toBeGreaterThanOrEqual(timing.domainLookupEnd); - expect(timing.secureConnectionStart).toBe(-1); - expect(timing.connectEnd).toBeGreaterThan(timing.secureConnectionStart); + verifyConnectionTimingConsistency(timing); expect(timing.requestStart).toBeGreaterThanOrEqual(timing.connectEnd); - expect(timing.responseStart).toBeGreaterThan(timing.requestStart); + expect(timing.responseStart).toBeGreaterThanOrEqual(timing.requestStart); expect(timing.responseEnd).toBeGreaterThanOrEqual(timing.responseStart); expect(timing.responseEnd).toBeLessThan(10000); }); -it('should work for subresource', async ({ page, server, isWindows, isWebKit }) => { +it('should work for subresource', async ({ page, server }) => { const requests = []; page.on('requestfinished', request => requests.push(request)); await page.goto(server.PREFIX + '/one-style.html'); expect(requests.length).toBe(2); const timing = requests[1].timing(); - if (isWebKit && isWindows) { - // Curl does not reuse connections. - expect(timing.domainLookupStart).toBeGreaterThanOrEqual(0); - expect(timing.domainLookupEnd).toBeGreaterThanOrEqual(timing.domainLookupStart); - expect(timing.connectStart).toBeGreaterThanOrEqual(timing.domainLookupEnd); - expect(timing.secureConnectionStart).toBe(-1); - expect(timing.connectEnd).toBeGreaterThan(timing.secureConnectionStart); - } else { - expect(timing.domainLookupStart === 0 || timing.domainLookupStart === -1).toBeTruthy(); - expect(timing.domainLookupEnd).toBe(-1); - expect(timing.connectStart).toBe(-1); - expect(timing.secureConnectionStart).toBe(-1); - expect(timing.connectEnd).toBe(-1); - } + verifyConnectionTimingConsistency(timing); expect(timing.requestStart).toBeGreaterThanOrEqual(0); expect(timing.responseStart).toBeGreaterThan(timing.requestStart); expect(timing.responseEnd).toBeGreaterThanOrEqual(timing.responseStart); expect(timing.responseEnd).toBeLessThan(10000); }); -it('should work for SSL', async ({ browser, httpsServer, isMac, isWebKit }) => { +it('should work for SSL', async ({ browser, httpsServer }) => { const page = await browser.newPage({ ignoreHTTPSErrors: true }); const [request] = await Promise.all([ page.waitForEvent('requestfinished'), page.goto(httpsServer.EMPTY_PAGE) ]); const timing = request.timing(); - if (!(isWebKit && isMac)) { - expect(timing.domainLookupStart).toBeGreaterThanOrEqual(0); - expect(timing.domainLookupEnd).toBeGreaterThanOrEqual(timing.domainLookupStart); - expect(timing.connectStart).toBeGreaterThanOrEqual(timing.domainLookupEnd); - expect(timing.secureConnectionStart).toBeGreaterThan(timing.connectStart); - expect(timing.connectEnd).toBeGreaterThan(timing.secureConnectionStart); - expect(timing.requestStart).toBeGreaterThanOrEqual(timing.connectEnd); - } + verifyConnectionTimingConsistency(timing); + expect(timing.requestStart).toBeGreaterThanOrEqual(timing.connectEnd); expect(timing.responseStart).toBeGreaterThan(timing.requestStart); expect(timing.responseEnd).toBeGreaterThanOrEqual(timing.responseStart); expect(timing.responseEnd).toBeLessThan(10000); @@ -95,24 +72,28 @@ it('should work for redirect', (test, { browserName }) => { expect(responses[1].url()).toBe(server.PREFIX + '/empty.html'); const timing1 = responses[0].request().timing(); - expect(timing1.domainLookupStart).toBeGreaterThanOrEqual(0); - expect(timing1.domainLookupEnd).toBeGreaterThanOrEqual(timing1.domainLookupStart); - expect(timing1.connectStart).toBeGreaterThanOrEqual(timing1.domainLookupEnd); - expect(timing1.secureConnectionStart).toBe(-1); - expect(timing1.connectEnd).toBeGreaterThan(timing1.secureConnectionStart); + verifyConnectionTimingConsistency(timing1); expect(timing1.requestStart).toBeGreaterThanOrEqual(timing1.connectEnd); expect(timing1.responseStart).toBeGreaterThan(timing1.requestStart); expect(timing1.responseEnd).toBeGreaterThanOrEqual(timing1.responseStart); expect(timing1.responseEnd).toBeLessThan(10000); const timing2 = responses[1].request().timing(); - expect(timing2.domainLookupStart).toBe(-1); - expect(timing2.domainLookupEnd).toBe(-1); - expect(timing2.connectStart).toBe(-1); - expect(timing2.secureConnectionStart).toBe(-1); - expect(timing2.connectEnd).toBe(-1); + verifyConnectionTimingConsistency(timing2); expect(timing2.requestStart).toBeGreaterThanOrEqual(0); expect(timing2.responseStart).toBeGreaterThan(timing2.requestStart); expect(timing2.responseEnd).toBeGreaterThanOrEqual(timing2.responseStart); expect(timing2.responseEnd).toBeLessThan(10000); }); + +function verifyTimingValue(value: number, previous: number) { + expect(value === -1 || value > 0 && value >= previous); +} + +function verifyConnectionTimingConsistency(timing) { + verifyTimingValue(timing.domainLookupStart, -1); + verifyTimingValue(timing.domainLookupEnd, timing.domainLookupStart); + verifyTimingValue(timing.connectStart, timing.domainLookupEnd); + verifyTimingValue(timing.secureConnectionStart, timing.connectStart); + verifyTimingValue(timing.connectEnd, timing.secureConnectionStart); +}