我正在用Mocha和Supertest測試Nodejs服務器。該測試套件已發展到超過1500個測試。突然,雖然所有被測試的代碼仍然有效,我的測試套件失敗,此錯誤:mocha supertest ECONNRESET
{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
如果我註釋掉早運行一些測試,導致錯誤變化的測試。 什麼導致了這種瘋狂?
我正在用Mocha和Supertest測試Nodejs服務器。該測試套件已發展到超過1500個測試。突然,雖然所有被測試的代碼仍然有效,我的測試套件失敗,此錯誤:mocha supertest ECONNRESET
{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
如果我註釋掉早運行一些測試,導致錯誤變化的測試。 什麼導致了這種瘋狂?
我找到了答案在此Google Groups post由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.
對我來說也是如此。
謝謝!這真的起作用了,爲我節省了很多麻煩! –
好的,但*爲什麼*它解決了這個問題?使用所有的臨時端口?當我獲得足夠的測試時,即使是第二版,我也遇到同樣的問題... –