Supertest在黄瓜延迟

我在黄瓜步骤文件中使用supertest向Docker中运行的API发出请求。 另外,我正在使用带有示例的场景大纲,以便请求被执行4次。

编辑:我发现,在黄瓜的第一个请求,我在我的docker日志中得到这个错误:“未能build立9P连接:抓住底层stream的EOF”。 但它只发生一次,从来没有从浏览器或邮递员。

given.js:

const request = require('supertest'); module.exports = function givens() { this.Given(/^then system is active$/, function (callback) { this.request = request.agent('http://localhost:8787'); callback(); }); } 

然后:

 module.exports = function whens() { this.When(/^the client requests a list of questions with the parameters of "([^"]*)" and "([^"]*)" and "([^"]*)" and "([^"]*)" and "([^"]*)" and "([^"]*)"$/, function (companyId, state, propertyType, yearBuilt, floodZone, active, callback) { var json = { ... }; this.request.post('/questions') .send(json) .set('Accept', 'application/json') .end((err, res) => { console.log(err); //return callback(); }); }); } 

问题在于响应延迟。 第一个请求返回一个错误:

 { Error: socket hang up at createHangUpError (_http_client.js:254:15) at Socket.socketOnEnd (_http_client.js:346:23) at emitNone (events.js:91:20) at Socket.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9) code: 'ECONNRESET', response: undefined } 

但是,如果我拿出callback,延迟后会得到正确的回应。 是什么导致第一个请求挂断? API请求在浏览器和Postman中正常工作。