我試圖模擬服務請求超時來測試節點requestretry模塊,它允許您指定請求最大嘗試重試次數和重試延遲時間。爲了測試這個,我需要使用nock模擬第一個X請求的超時,然後成功響應相同的請求。我知道有'socketDelay()'方法來延遲連接,但是如何在第一次延遲響應之後指定一個成功的響應?Node.js Nock模擬請求超時和後續成功
我有這個,模擬在第一次請求
//delays the first request's response by 1500
nock(urlHost)
.post('/' + uriPath)
.socketDelay(1500)
.reply(200, 'response body');
,但我怎麼能做出迴應之後更快地模擬服務恢復超時?我期待繼續沿着這條
//delays the first two request's responses by 1500
nock(urlHost)
.post('/' + requestIdentifier.ttoRoutingInfo.uriPath)
.socketDelay(1500)
.reply(200, 'response body')
.times(2)
//delays the third request by only 300
.then
.socketDelay(300)
.reply(200, 'response body');