Skip to content

Commit 76e8e9f

Browse files
authored
fix: 'Memory leak on running more than 11 tests' (close #7188) (#7199)
* fix 'Memory leak on running more than 11 tests' (close #7188) * fix tests in firefox
1 parent 68cc8d6 commit 76e8e9f

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

src/browser/provider/built-in/dedicated/chrome/cdp-client/index.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ export class BrowserClient {
5151
private readonly _runtimeInfo: RuntimeInfo;
5252
private _parentTarget?: remoteChrome.TargetInfo;
5353
private readonly debugLogger: debug.Debugger;
54-
private readonly _videoFramesBuffer: VideoFrameData[];
54+
private _videoFramesBuffer: VideoFrameData[];
5555
private _lastFrame: VideoFrameData | null;
56+
private _screencastFrameListenerAttached = false;
5657

5758
public constructor (runtimeInfo: RuntimeInfo) {
5859
this._runtimeInfo = runtimeInfo;
@@ -358,16 +359,32 @@ export class BrowserClient {
358359
if (!client)
359360
return;
360361

361-
client.Page.on('screencastFrame', (event: ScreencastFrameEvent) => {
362-
this._videoFramesBuffer.push({
363-
data: event.data,
364-
sessionId: event.sessionId,
362+
if (!this._screencastFrameListenerAttached) {
363+
client.Page.on('screencastFrame', (event: ScreencastFrameEvent) => {
364+
this._videoFramesBuffer.push({
365+
data: event.data,
366+
sessionId: event.sessionId,
367+
});
365368
});
366-
});
369+
370+
this._screencastFrameListenerAttached = true;
371+
}
367372

368373
await client.Page.startScreencast(SCREENCAST_OPTIONS as StartScreencastRequest);
369374
}
370375

376+
public async stopCapturingVideo (): Promise<void> {
377+
const client = await this.getActiveClient();
378+
379+
if (!client)
380+
return;
381+
382+
await client.Page.stopScreencast();
383+
384+
this._lastFrame = null;
385+
this._videoFramesBuffer = [];
386+
}
387+
371388
public async getVideoFrameData (): Promise<Buffer | null> {
372389
const currentVideoFrame = this._videoFramesBuffer.shift() || this._lastFrame;
373390

src/browser/provider/built-in/dedicated/chrome/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ export default {
128128
await browserClient.startCapturingVideo();
129129
},
130130

131+
async stopCapturingVideo (browserId) {
132+
const { browserClient } = this.openedBrowsers[browserId];
133+
134+
await browserClient.stopCapturingVideo();
135+
},
136+
131137
async getVideoFrameData (browserId) {
132138
const { browserClient } = this.openedBrowsers[browserId];
133139

src/browser/provider/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ export default class BrowserProvider {
417417
await this.plugin.startCapturingVideo(browserId);
418418
}
419419

420+
public async stopCapturingVideo (browserId: string): Promise<void> {
421+
await this.plugin.stopCapturingVideo(browserId);
422+
}
423+
420424
public async hasCustomActionForBrowser (browserId: string): Promise<any> {
421425
return this.plugin.hasCustomActionForBrowser(browserId);
422426
}

src/browser/provider/plugin-host.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ export default class BrowserProviderPluginHost {
143143
async startCapturingVideo (/*browserId*/) {
144144
}
145145

146+
async stopCapturingVideo (/*browserId*/) {
147+
}
148+
146149
async getVideoFrameData (browserId) {
147150
const browserAlias = BrowserConnection.getById(browserId).browserInfo.alias;
148151

src/video-recorder/process.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export default class VideoRecorder extends AsyncEmitter {
130130
await this.connection.provider.startCapturingVideo(this.connection.id);
131131
}
132132

133+
async _stopCapturing () {
134+
await this.connection.provider.stopCapturingVideo(this.connection.id);
135+
}
136+
133137
async init () {
134138
this.ffmpegProcess = spawn(this.ffmpegPath, this.optionsList, { stdio: 'pipe' });
135139

@@ -183,6 +187,7 @@ export default class VideoRecorder extends AsyncEmitter {
183187

184188
this.closed = true;
185189

190+
await this._stopCapturing();
186191
await this.capturingPromise;
187192
await this.dispose();
188193
}

0 commit comments

Comments
 (0)