fix: stop har recording when APIRequestContext is disposed (#17007)

This commit is contained in:
Yury Semikhatsky 2022-08-31 21:51:38 -07:00 committed by GitHub
parent 535f3d1564
commit 5d6253f743
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 9 deletions

View file

@ -216,7 +216,7 @@ export abstract class BrowserContext extends SdkObject {
this._closedStatus = 'closed'; this._closedStatus = 'closed';
this._deleteAllDownloads(); this._deleteAllDownloads();
this._downloads.clear(); this._downloads.clear();
this.tracing.dispose(); this.tracing.dispose().catch(() => {});
if (this._isPersistentContext) if (this._isPersistentContext)
this.onClosePersistent(); this.onClosePersistent();
this._closePromiseFulfill!(new Error('Context closed')); this._closePromiseFulfill!(new Error('Context closed'));
@ -389,7 +389,7 @@ export abstract class BrowserContext extends SdkObject {
for (const harRecorder of this._harRecorders.values()) for (const harRecorder of this._harRecorders.values())
await harRecorder.flush(); await harRecorder.flush();
await this.tracing.flush(); await this.tracing.dispose();
// Cleanup. // Cleanup.
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];

View file

@ -509,9 +509,8 @@ export class GlobalAPIRequestContext extends APIRequestContext {
} }
override async dispose() { override async dispose() {
await this._tracing.flush(); await this._tracing.dispose();
await this._tracing.deleteTmpTracesDir(); await this._tracing.deleteTmpTracesDir();
this._tracing.dispose();
this._disposeImpl(); this._disposeImpl();
} }

View file

@ -200,13 +200,10 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
return this._tracesTmpDir; return this._tracesTmpDir;
} }
async flush() {
this._snapshotter?.dispose();
await this._writeChain;
}
async dispose() { async dispose() {
this._snapshotter?.dispose(); this._snapshotter?.dispose();
this._harTracer.stop();
await this._writeChain;
} }
async stopChunk(params: TracingTracingStopChunkParams): Promise<{ artifact: Artifact | null, sourceEntries: NameValue[] | undefined }> { async stopChunk(params: TracingTracingStopChunkParams): Promise<{ artifact: Artifact | null, sourceEntries: NameValue[] | undefined }> {

View file

@ -50,3 +50,37 @@ test('should use baseURL in request fixture', async ({ runInlineTest, server })
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1); expect(result.passed).toBe(1);
}); });
test('should stop tracing on requestContex.dispose()', async ({ runInlineTest, server }) => {
server.setRoute('/slow', (req, resp) => {
resp.writeHead(200, {
'Content-Type': 'text/plain; charset=utf-8',
'Content-Length': '3',
});
setTimeout(() => {
resp.end('Hi!');
}, 500);
});
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
reporter: 'html',
use: {
browserName: 'firefox',
trace:'retain-on-failure'
}
};
`,
'a.test.ts': `
const { test } = pwt;
test('hanging request', async ({ page, request }) => {
const response = await page.goto('${server.EMPTY_PAGE}');
expect(response.status()).toBe(200);
await request.get('${server.PREFIX}/slow');
});
`,
}, { workers: 1, timeout: 1000 });
expect(result.output).not.toContain('ENOENT');
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
});