mocha supertest ECONNRESET

2019-03-29 14:13发布

I'm testing a Nodejs server with Mocha and Supertest. The test suite has grown to more than 1500 tests. Suddenly, although all of the code under test still works, my test suite fails with this error:

{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

If I comment out some tests that run earlier, the tests that cause the error change. What is causing this insanity?

1条回答
Juvenile、少年°
2楼-- · 2019-03-29 14:33

I found the answer in this Google Groups post by Mike Gradek:

We used mocha and supertest to issue these requests, and realized that we were actually spinning up new port bindings on every request instead of reusing existing bindings.

So code that was written like so:

var request = require('supertest');
var app = require('../app');
request(app).get(...);
request(app).get(...);

Became

var request = require('supertest');
var app = require('../app');
var supertest = request(app);
supertest.get(...);
supertest.get(...);

That solved the issue for us.

And for me as well.

查看更多
登录 后发表回答