I'm trying to simulate service request timeouts to test the node requestretry module, which allows you to specify a request max # of attempted retries and retry delay. In order to test this, I need to use nock to simulate a timeout for the first X number of requests, then respond successfully to the same request. I know there is the 'socketDelay()' method to delay the connection, but how do I specify a successful response after that first delayed response?
I have this, which simulates a timeout on the first request
//delays the first request's response by 1500
nock(urlHost)
.post('/' + uriPath)
.socketDelay(1500)
.reply(200, 'response body');
but how can I make it respond faster after that to simulate the service recovering? I'm looking to do something along these lines
//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');