mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-27 13:50:25 +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}) => {
|
||||
const e = await browserType.connect({
|
||||
wsEndpoint: `ws://localhost:${server.PORT}/ws`,
|
||||
timeout: 1,
|
||||
wsEndpoint: `ws://localhost:${server.PORT}/ws-slow`,
|
||||
timeout: 1000,
|
||||
}).catch(e => e);
|
||||
expect(e.message).toContain('browserType.connect: Opening handshake has timed out');
|
||||
});
|
||||
|
@ -70,17 +70,24 @@ class TestServer {
|
||||
else
|
||||
this._server = http.createServer(this._onRequest.bind(this));
|
||||
this._server.on('connection', socket => this._onSocket(socket));
|
||||
this._wsServer = new WebSocketServer({server: this._server });
|
||||
this._wsServer.shouldHandle = (request) => {
|
||||
this._wsServer = new WebSocketServer({ noServer: true });
|
||||
this._server.on('upgrade', async (request, socket, head) => {
|
||||
const pathname = url.parse(request.url).pathname;
|
||||
return ['/ws', '/ws-emit-and-close'].includes(pathname);
|
||||
};
|
||||
this._wsServer.on('connection', (ws, request) => {
|
||||
const pathname = url.parse(request.url).pathname;
|
||||
if (this._onWebSocketConnectionData !== undefined)
|
||||
ws.send(this._onWebSocketConnectionData);
|
||||
if (pathname === '/ws-emit-and-close')
|
||||
ws.close(1003, 'closed by Playwright test-server');
|
||||
if (pathname === '/ws-slow')
|
||||
await new Promise(f => setTimeout(f, 2000));
|
||||
if (!['/ws', '/ws-slow', '/ws-emit-and-close'].includes(pathname)) {
|
||||
socket.write('HTTP/1.1 400 Bad Request\r\n\r\n');
|
||||
socket.destroy();
|
||||
return;
|
||||
}
|
||||
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._dirPath = dirPath;
|
||||
|
Loading…
Reference in New Issue
Block a user