mocha supertest ECONNRESET

不羁的心 提交于 2019-12-09 13:07:19

问题


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:


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.



来源:https://stackoverflow.com/questions/21948296/mocha-supertest-econnreset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!