我在黄瓜步骤文件中使用supertest向我在docker中运行的API发出请求。此外,我使用了一个带有示例的场景大纲,因此请求进行了4次。
编辑:我发现在黄瓜的第一个请求中,我的docker日志中出现此错误:'未能建立9P连接:在基础FLOW上捕获EOF'。但它只发生一次,而不是从浏览器或邮差发生。given.js:
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 }
问题在于响应有延迟。第一个请求返回错误:
Dim words(0) As String = String.Empty
Dim trie As String = String.Empty
Dim temp As String = String.Empty
For i = 1 To 26
trie = encrypt(a, -i)
Console.WriteLine(trie)
For j = 0 To words.Length - 1
temp = words(j)
If Not temp Is Nothing AndAlso _
Not trie Is Nothing AndAlso _
trie.Contains(temp) Then
Console.ReadLine()
End If
Next
Next
但如果我取出回调,它会在延迟后获得正确的回复。导致第一个请求挂断的原因是什么? API请求在浏览器和Postman中正常工作。