mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: unflake 'android.launchServer' WS leak test (#28891)
This test was flaky all the time. The problem was that we were sending messages on a WS connection which wasn't ready yet, so we lost some.
This commit is contained in:
parent
67478efe92
commit
1d8c6d4760
@ -118,14 +118,16 @@ test('android.launchServer should terminate WS connection when device gets disco
|
|||||||
const forwardingServer = new ws.Server({ port: 0, path: '/connect' });
|
const forwardingServer = new ws.Server({ port: 0, path: '/connect' });
|
||||||
let receivedConnection: ws.WebSocket | undefined;
|
let receivedConnection: ws.WebSocket | undefined;
|
||||||
forwardingServer.on('connection', connection => {
|
forwardingServer.on('connection', connection => {
|
||||||
|
// Pause the connection until we establish the actual connection to the browser server.
|
||||||
|
connection.pause();
|
||||||
receivedConnection = connection;
|
receivedConnection = connection;
|
||||||
const actualConnection = new ws.WebSocket(browserServer.wsEndpoint());
|
const actualConnection = new ws.WebSocket(browserServer.wsEndpoint());
|
||||||
actualConnection.on('open', () => {
|
// We need to wait for the actual connection to be established before resuming
|
||||||
actualConnection.on('message', message => connection.send(message));
|
actualConnection.on('open', () => connection.resume());
|
||||||
connection.on('message', message => actualConnection.send(message));
|
actualConnection.on('message', message => connection.send(message));
|
||||||
connection.on('close', () => actualConnection.close());
|
connection.on('message', message => actualConnection.send(message));
|
||||||
actualConnection.on('close', () => connection.close());
|
connection.on('close', () => actualConnection.close());
|
||||||
});
|
actualConnection.on('close', () => connection.close());
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
const device = await playwright._android.connect(`ws://localhost:${(forwardingServer.address() as ws.AddressInfo).port}/connect`);
|
const device = await playwright._android.connect(`ws://localhost:${(forwardingServer.address() as ws.AddressInfo).port}/connect`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user