Skip to content

Commit

Permalink
fix: 'Memory leak on running more than 11 tests' (close #7188) (#7199)
Browse files Browse the repository at this point in the history
* fix 'Memory leak on running more than 11 tests' (close #7188)

* fix tests in firefox
  • Loading branch information
miherlosev committed Jul 28, 2022
1 parent 68cc8d6 commit 76e8e9f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/browser/provider/built-in/dedicated/chrome/cdp-client/index.ts
Expand Up @@ -51,8 +51,9 @@ export class BrowserClient {
private readonly _runtimeInfo: RuntimeInfo;
private _parentTarget?: remoteChrome.TargetInfo;
private readonly debugLogger: debug.Debugger;
private readonly _videoFramesBuffer: VideoFrameData[];
private _videoFramesBuffer: VideoFrameData[];
private _lastFrame: VideoFrameData | null;
private _screencastFrameListenerAttached = false;

public constructor (runtimeInfo: RuntimeInfo) {
this._runtimeInfo = runtimeInfo;
Expand Down Expand Up @@ -358,16 +359,32 @@ export class BrowserClient {
if (!client)
return;

client.Page.on('screencastFrame', (event: ScreencastFrameEvent) => {
this._videoFramesBuffer.push({
data: event.data,
sessionId: event.sessionId,
if (!this._screencastFrameListenerAttached) {
client.Page.on('screencastFrame', (event: ScreencastFrameEvent) => {
this._videoFramesBuffer.push({
data: event.data,
sessionId: event.sessionId,
});
});
});

this._screencastFrameListenerAttached = true;
}

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

public async stopCapturingVideo (): Promise<void> {
const client = await this.getActiveClient();

if (!client)
return;

await client.Page.stopScreencast();

this._lastFrame = null;
this._videoFramesBuffer = [];
}

public async getVideoFrameData (): Promise<Buffer | null> {
const currentVideoFrame = this._videoFramesBuffer.shift() || this._lastFrame;

Expand Down
6 changes: 6 additions & 0 deletions src/browser/provider/built-in/dedicated/chrome/index.js
Expand Up @@ -128,6 +128,12 @@ export default {
await browserClient.startCapturingVideo();
},

async stopCapturingVideo (browserId) {
const { browserClient } = this.openedBrowsers[browserId];

await browserClient.stopCapturingVideo();
},

async getVideoFrameData (browserId) {
const { browserClient } = this.openedBrowsers[browserId];

Expand Down
4 changes: 4 additions & 0 deletions src/browser/provider/index.ts
Expand Up @@ -417,6 +417,10 @@ export default class BrowserProvider {
await this.plugin.startCapturingVideo(browserId);
}

public async stopCapturingVideo (browserId: string): Promise<void> {
await this.plugin.stopCapturingVideo(browserId);
}

public async hasCustomActionForBrowser (browserId: string): Promise<any> {
return this.plugin.hasCustomActionForBrowser(browserId);
}
Expand Down
3 changes: 3 additions & 0 deletions src/browser/provider/plugin-host.js
Expand Up @@ -143,6 +143,9 @@ export default class BrowserProviderPluginHost {
async startCapturingVideo (/*browserId*/) {
}

async stopCapturingVideo (/*browserId*/) {
}

async getVideoFrameData (browserId) {
const browserAlias = BrowserConnection.getById(browserId).browserInfo.alias;

Expand Down
5 changes: 5 additions & 0 deletions src/video-recorder/process.js
Expand Up @@ -130,6 +130,10 @@ export default class VideoRecorder extends AsyncEmitter {
await this.connection.provider.startCapturingVideo(this.connection.id);
}

async _stopCapturing () {
await this.connection.provider.stopCapturingVideo(this.connection.id);
}

async init () {
this.ffmpegProcess = spawn(this.ffmpegPath, this.optionsList, { stdio: 'pipe' });

Expand Down Expand Up @@ -183,6 +187,7 @@ export default class VideoRecorder extends AsyncEmitter {

this.closed = true;

await this._stopCapturing();
await this.capturingPromise;
await this.dispose();
}
Expand Down

0 comments on commit 76e8e9f

Please sign in to comment.