ECONNRESET when running "many" tests
See original GitHub issueHey there,
we run into random ECONNRESET
problems for weeks now and tried many things to mitigate the problem. We use supertest for e2e testing a GraphQL API built with Nest.js.
We run it like so:
GraphQLQuery.ts
:
export class GraphQlQuery {
private static _bindings: Map<string, supertest.SuperTest<supertest.Test>>;
static queryGraphQl(app: INestApplication, query: GraphQlQuery, token?: string): supertest.Test {
if (!GraphQlQuery._bindings) {
GraphQlQuery._bindings = new Map();
}
let binding = GraphQlQuery._bindings.get(app.getHttpServer().testHash);
if (!binding) {
binding = request(app.getHttpServer());
GraphQlQuery._bindings.set(app.getHttpServer().testHash, binding);
}
const req = binding.post("/graphql");
if (token) {
req.set({ Authorization: `Bearer ${token}` });
}
req.send({ operationName: null, query: query.build() })
.expect((response) => {
if (!response.ok) {
console.error(JSON.stringify(response, null, 2));
}
})
.expect(200);
return req;
}
// ...
}
Somewhere in the tests, we can then do
GraphQlQuery.queryGraphQl(app, query, jwt).then((response) => {
expect(response).toBe(something);
});
The reason we do all the GraphQLQuery._bindings
-stuff is because we are aware that those bindings should be reused. We create the Nest.js app in our beforeAll()
-hooks, where we also add the testHash
to the HTTP Server. It’s basically a UUID to ensure that we can map bindings to test-suites. We also run Jest with --runInBand
on the CI, so nothing should run concurrently. We have around 80 tests now which all rely on supertest and the more tests we build, the worse it gets. Up until to a point where we need to run the whole CI-step multiple times until ECONNRESET
doesn’t happen any more. Sometimes up to 10 times or so, with each pipeline needing ~5 minutes.
Unfortunately I didn’t find much information about our problems and since Nest.js recommends supertest (and I think I can say that on behalf of the team, we really like the approach), I am wondering what we’re missing.
Any help appreciated!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:12 (2 by maintainers)
Top GitHub Comments
I wrote test to reproduce problem
There are may be different output in terminal after executions:
or
etc.
But i have no idea how to fix this 😦
And assign it to me I’ll fix it later on this week.