Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] supertest fails with intermittent "socket hang up" in loops #844

Open
ikonst opened this issue Oct 22, 2024 · 0 comments · May be fixed by #846
Open

[fix] supertest fails with intermittent "socket hang up" in loops #844

ikonst opened this issue Oct 22, 2024 · 0 comments · May be fixed by #846
Labels

Comments

@ikonst
Copy link

ikonst commented Oct 22, 2024

When testing a rate limiting feature, I've encountered intermittent low level errors in the form of "socket hang up", etc.

What I found to reliably work around this, is to create a supertest agent for a listening(!) HTTP server rather than an ExpressJS app, i.e.

 const app = express();
 app.get("/", (req, res) => res.send("OK"));
-const superAgent = request(app);
+const server = http.createServer(app).listen(0);
+const superAgent = request(server);

 for (let i = 0; i < 1000; i++) {
   await superAgent.get("/").expect(200);
 }

Maybe it's possible to do the server.listen(0) on the TestAgent level so it doesn't have to be repeated for every request, and thus sometimes fail (e.g. for port allocation reasons).

@ikonst ikonst added the bug label Oct 22, 2024
@ikonst ikonst linked a pull request Nov 9, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant