diff --git a/tests/config/serverFixtures.ts b/tests/config/serverFixtures.ts index b779c224d5..0d73a84ac8 100644 --- a/tests/config/serverFixtures.ts +++ b/tests/config/serverFixtures.ts @@ -49,9 +49,11 @@ export const serverFixtures: Fixtures = { const socksServer = socks.createServer((info, accept, deny) => { const socket = accept(true); - if (socket) { - // Catch and ignore ECONNRESET errors. - socket.on('error', () => {}); + if (!socket) + return; + socket.on('data', data => { + if (!data.toString().includes('\r\n\r\n')) + return; const body = 'Served by the SOCKS proxy'; socket.end([ 'HTTP/1.1 200 OK', @@ -61,7 +63,10 @@ export const serverFixtures: Fixtures = { '', body ].join('\r\n')); - } + }); + // Catch and ignore ECONNRESET errors. + socket.on('error', () => {}); + setTimeout(() => socket.end(), 1000); }); const socksPort = port + 2; socksServer.listen(socksPort, 'localhost');