fix(server): use setMaxListeners(0) on all internal event emitters (#5283)
This commit is contained in:
Родитель
3d253c4e5c
Коммит
d8e0834562
|
@ -119,6 +119,7 @@ export class AndroidDevice extends EventEmitter {
|
|||
|
||||
constructor(android: Android, backend: DeviceBackend, model: string) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._android = android;
|
||||
this._backend = backend;
|
||||
this.model = model;
|
||||
|
@ -385,6 +386,7 @@ class AndroidBrowser extends EventEmitter {
|
|||
|
||||
constructor(device: AndroidDevice, socket: SocketBackend) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this.device = device;
|
||||
this._socket = socket;
|
||||
this._socket.on('close', () => {
|
||||
|
|
|
@ -109,6 +109,7 @@ class BufferedSocketWrapper extends EventEmitter implements SocketBackend {
|
|||
|
||||
constructor(command: string, socket: net.Socket) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._command = command;
|
||||
this._socket = socket;
|
||||
this._connectPromise = new Promise(f => this._socket.on('connect', f));
|
||||
|
|
|
@ -61,6 +61,7 @@ export abstract class Browser extends EventEmitter {
|
|||
|
||||
constructor(options: BrowserOptions) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ export abstract class BrowserContext extends EventEmitter {
|
|||
|
||||
constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._browser = browser;
|
||||
this._options = options;
|
||||
this._browserContextId = browserContextId;
|
||||
|
|
|
@ -43,6 +43,7 @@ export class CRConnection extends EventEmitter {
|
|||
|
||||
constructor(transport: ConnectionTransport, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._transport = transport;
|
||||
this._protocolLogger = protocolLogger;
|
||||
this._browserLogsCollector = browserLogsCollector;
|
||||
|
@ -139,6 +140,7 @@ export class CRSession extends EventEmitter {
|
|||
|
||||
constructor(connection: CRConnection, rootSessionId: string, targetType: string, sessionId: string) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._connection = connection;
|
||||
this._rootSessionId = rootSessionId;
|
||||
this._targetType = targetType;
|
||||
|
|
|
@ -65,6 +65,7 @@ export class ElectronApplication extends EventEmitter {
|
|||
|
||||
constructor(browser: CRBrowser, nodeConnection: CRConnection) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._browserContext = browser._defaultContext as CRBrowserContext;
|
||||
this._browserContext.on(BrowserContext.Events.Close, () => {
|
||||
// Emit application closed after context closed.
|
||||
|
|
|
@ -49,6 +49,7 @@ export class FFConnection extends EventEmitter {
|
|||
|
||||
constructor(transport: ConnectionTransport, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._transport = transport;
|
||||
this._protocolLogger = protocolLogger;
|
||||
this._browserLogsCollector = browserLogsCollector;
|
||||
|
@ -162,6 +163,7 @@ export class FFSession extends EventEmitter {
|
|||
|
||||
constructor(connection: FFConnection, targetType: string, sessionId: string, rawSend: (message: any) => void) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._callbacks = new Map();
|
||||
this._connection = connection;
|
||||
this._targetType = targetType;
|
||||
|
|
|
@ -355,6 +355,7 @@ export class WebSocket extends EventEmitter {
|
|||
|
||||
constructor(url: string) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._url = url;
|
||||
}
|
||||
|
||||
|
|
|
@ -508,6 +508,7 @@ export class Worker extends EventEmitter {
|
|||
|
||||
constructor(url: string) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._url = url;
|
||||
this._executionContextCallback = () => {};
|
||||
this._executionContextPromise = new Promise(x => this._executionContextCallback = x);
|
||||
|
|
|
@ -28,11 +28,11 @@ import { DEFAULT_ARGS } from '../../chromium/chromium';
|
|||
const readFileAsync = util.promisify(fs.readFile);
|
||||
|
||||
export class RecorderApp extends EventEmitter {
|
||||
|
||||
private _page: Page;
|
||||
|
||||
constructor(page: Page) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this._page = page;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ export class WKSession extends EventEmitter {
|
|||
|
||||
constructor(connection: WKConnection, sessionId: string, errorText: string, rawSend: (message: any) => void) {
|
||||
super();
|
||||
this.setMaxListeners(0);
|
||||
this.connection = connection;
|
||||
this.sessionId = sessionId;
|
||||
this._rawSend = rawSend;
|
||||
|
|
|
@ -256,4 +256,18 @@ describe('connect', (suite, { mode }) => {
|
|||
const files = fs.readdirSync(videosPath);
|
||||
expect(files.some(file => file.endsWith('webm'))).toBe(true);
|
||||
});
|
||||
|
||||
it('should be able to connect 20 times to a single server without warnings', async ({browserType, remoteServer, server}) => {
|
||||
let warning = null;
|
||||
const warningHandler = w => warning = w;
|
||||
process.on('warning', warningHandler);
|
||||
|
||||
const browsers = [];
|
||||
for (let i = 0; i < 20; i++)
|
||||
browsers.push(await browserType.connect({ wsEndpoint: remoteServer.wsEndpoint() }));
|
||||
await Promise.all([browsers.map(browser => browser.close())]);
|
||||
|
||||
process.off('warning', warningHandler);
|
||||
expect(warning).toBe(null);
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче