I'm using supertest in cucumber step files to make a request to my API running in docker. Also, I'm using a Scenario Outline with Examples so the request is made 4 times.
EDIT: I found that on the first request in cucumber I get this error in my docker logs: 'failed to establish 9P connection: Caught EOF on underlying FLOW'. But it only happens once and never from the browser or Postman.
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();
});
}
then:
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();
});
});
}
The problem is that there is a delay in the response. The first request returns an error:
{ 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 }
But if I take out the callbacks it will get the correct responses after a delay. What is causing the first request to hang up? The API request works fine in the browser and Postman.