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