From 56a7adeb8ae316c14cefeddc48d67187b4d28d0e Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 12 Apr 2024 19:48:53 +0200 Subject: [PATCH] test: unflake 'should not include trace resources from the previous chunks' test (#30257) --- .../playwright-core/src/client/browserContext.ts | 1 + packages/playwright-core/src/client/fetch.ts | 1 + packages/playwright-core/src/client/tracing.ts | 12 ++++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index 5747c822e1..f8f8977313 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -432,6 +432,7 @@ export class BrowserContext extends ChannelOwner this._browser._contexts.delete(this); this._browserType?._contexts?.delete(this); this._disposeHarRouters(); + this.tracing._resetStackCounter(); this.emit(Events.BrowserContext.Close, this); } diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.ts index 8dc3caa570..13a0c0e643 100644 --- a/packages/playwright-core/src/client/fetch.ts +++ b/packages/playwright-core/src/client/fetch.ts @@ -102,6 +102,7 @@ export class APIRequestContext extends ChannelOwner { await this._instrumentation.onWillCloseRequestContext(this); await this._channel.dispose(); + this._tracing._resetStackCounter(); this._request?._contexts.delete(this); } diff --git a/packages/playwright-core/src/client/tracing.ts b/packages/playwright-core/src/client/tracing.ts index c90cdfcee6..7330cd9f26 100644 --- a/packages/playwright-core/src/client/tracing.ts +++ b/packages/playwright-core/src/client/tracing.ts @@ -76,10 +76,7 @@ export class Tracing extends ChannelOwner implements ap } private async _doStopChunk(filePath: string | undefined) { - if (this._isTracing) { - this._isTracing = false; - this._connection.setIsTracing(false); - } + this._resetStackCounter(); if (!filePath) { // Not interested in artifacts. @@ -113,4 +110,11 @@ export class Tracing extends ChannelOwner implements ap await this._connection.localUtils()._channel.zip({ zipFile: filePath, entries: [], mode: 'append', stacksId: this._stacksId, includeSources: this._includeSources }); } + + _resetStackCounter() { + if (this._isTracing) { + this._isTracing = false; + this._connection.setIsTracing(false); + } + } }