Concurrent requests result in ECONNREFUSED
Hi there! 👋
I am attempting to write an integration test case with supertest in which a couple requests are sent to the app concurrently. However, I get an ECONNREFUSED error when the test is executed. Is it possible to support concurrent requests?
Attempted usage:
it('can make concurrent GET requests to the app', async () => {
const request1 = testApp.get('/');
const request2 = testApp.get('/');
await request1.expect(200);
await request2.expect(200);
});
Here is a demo repo where the issue can be easily reproduced: https://github.com/Drew-Kimberly/supertest-repro
This can be done by using a slightly different implementation (by leveraging the end callback):
const app = require('./app');
const request = require('supertest');
let testApp;
const makeGetRequest = path => new Promise((resolve, reject) => {
testApp.get(path).end((err, res) => {
if (err) {
return reject(err);
}
resolve(res);
});
});
beforeEach(() => {
testApp = request(app);
});
it('can make concurrent GET requests to the app', async () => {
const request1 = makeGetRequest('/');
const request2 = makeGetRequest('/');
await request1;
await request2;
});
Demonstrated in this branch: https://github.com/Drew-Kimberly/supertest-repro/tree/workaround
I'm going to leave this open just to get some thoughts on why the first implementation results in the hard error.
We get a few flakes, around 2-3 each test run in our codebase with ~2000 tests
(same stack trace but with EHOSTUNREACH)