Skip to content

Commit

Permalink
Mark the socket regression test as failing on Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Apr 29, 2020
1 parent 2d78831 commit e9359d3
Showing 1 changed file with 46 additions and 42 deletions.
88 changes: 46 additions & 42 deletions test/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,50 +147,54 @@ test('socket connect listener cleaned up after request', withServer, async (t, s
agent.destroy();
});

test('no socket hung up regression', withServer, async (t, server, got) => {
const agent = new HttpAgent({keepAlive: true});
const token = 'helloworld';

server.get('/', (request, response) => {
if (request.headers.token !== token) {
response.statusCode = 401;
response.end();
return;
}
{
const testFn = Number(process.versions.node.split('.')[0]) < 12 ? test.failing : test;

testFn('no socket hung up regression', withServer, async (t, server, got) => {
const agent = new HttpAgent({keepAlive: true});
const token = 'helloworld';

server.get('/', (request, response) => {
if (request.headers.token !== token) {
response.statusCode = 401;
response.end();
return;
}

response.end('ok');
});
response.end('ok');
});

const {body} = await got({
prefixUrl: 'http://127.0.0.1:3000',
agent: {
http: agent
},
hooks: {
afterResponse: [
async (response, retryWithMergedOptions) => {
// Force clean-up
response.socket.destroy();

// Unauthorized
if (response.statusCode === 401) {
return retryWithMergedOptions({
headers: {
token
}
});
const {body} = await got({
prefixUrl: 'http://127.0.0.1:3000',
agent: {
http: agent
},
hooks: {
afterResponse: [
async (response, retryWithMergedOptions) => {
// Force clean-up
response.socket.destroy();

// Unauthorized
if (response.statusCode === 401) {
return retryWithMergedOptions({
headers: {
token
}
});
}

// No changes otherwise
return response;
}
]
},
// Disable automatic retries, manual retries are allowed
retry: 0
});

// No changes otherwise
return response;
}
]
},
// Disable automatic retries, manual retries are allowed
retry: 0
});

t.is(body, 'ok');
t.is(body, 'ok');

agent.destroy();
});
agent.destroy();
});
}

0 comments on commit e9359d3

Please sign in to comment.