Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 'Memory leak on running more than 11 tests' (close #7188) #7199

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/browser/provider/built-in/dedicated/chrome/cdp-client/index.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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