mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-27 21:58:52 +03:00
test: unflake "should timeout in socket while connecting" (#9093)
This commit is contained in:
parent
568ec05a97
commit
e6f5404621
@ -104,8 +104,8 @@ test('should be able to connect two browsers at the same time', async ({browserT
|
|||||||
|
|
||||||
test('should timeout in socket while connecting', async ({browserType, startRemoteServer, server}) => {
|
test('should timeout in socket while connecting', async ({browserType, startRemoteServer, server}) => {
|
||||||
const e = await browserType.connect({
|
const e = await browserType.connect({
|
||||||
wsEndpoint: `ws://localhost:${server.PORT}/ws`,
|
wsEndpoint: `ws://localhost:${server.PORT}/ws-slow`,
|
||||||
timeout: 1,
|
timeout: 1000,
|
||||||
}).catch(e => e);
|
}).catch(e => e);
|
||||||
expect(e.message).toContain('browserType.connect: Opening handshake has timed out');
|
expect(e.message).toContain('browserType.connect: Opening handshake has timed out');
|
||||||
});
|
});
|
||||||
|
@ -70,17 +70,24 @@ class TestServer {
|
|||||||
else
|
else
|
||||||
this._server = http.createServer(this._onRequest.bind(this));
|
this._server = http.createServer(this._onRequest.bind(this));
|
||||||
this._server.on('connection', socket => this._onSocket(socket));
|
this._server.on('connection', socket => this._onSocket(socket));
|
||||||
this._wsServer = new WebSocketServer({server: this._server });
|
this._wsServer = new WebSocketServer({ noServer: true });
|
||||||
this._wsServer.shouldHandle = (request) => {
|
this._server.on('upgrade', async (request, socket, head) => {
|
||||||
const pathname = url.parse(request.url).pathname;
|
const pathname = url.parse(request.url).pathname;
|
||||||
return ['/ws', '/ws-emit-and-close'].includes(pathname);
|
if (pathname === '/ws-slow')
|
||||||
};
|
await new Promise(f => setTimeout(f, 2000));
|
||||||
this._wsServer.on('connection', (ws, request) => {
|
if (!['/ws', '/ws-slow', '/ws-emit-and-close'].includes(pathname)) {
|
||||||
const pathname = url.parse(request.url).pathname;
|
socket.write('HTTP/1.1 400 Bad Request\r\n\r\n');
|
||||||
if (this._onWebSocketConnectionData !== undefined)
|
socket.destroy();
|
||||||
ws.send(this._onWebSocketConnectionData);
|
return;
|
||||||
if (pathname === '/ws-emit-and-close')
|
}
|
||||||
ws.close(1003, 'closed by Playwright test-server');
|
this._wsServer.handleUpgrade(request, socket, head, ws => {
|
||||||
|
// Next emit is only for our internal 'connection' listeners.
|
||||||
|
this._wsServer.emit('connection', ws, request);
|
||||||
|
if (this._onWebSocketConnectionData !== undefined)
|
||||||
|
ws.send(this._onWebSocketConnectionData);
|
||||||
|
if (pathname === '/ws-emit-and-close')
|
||||||
|
ws.close(1003, 'closed by Playwright test-server');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
this._server.listen(port);
|
this._server.listen(port);
|
||||||
this._dirPath = dirPath;
|
this._dirPath = dirPath;
|
||||||
|
Loading…
Reference in New Issue
Block a user