【发布时间】:2015-10-11 10:06:14
【问题描述】:
我正在尝试模拟服务请求超时以测试节点 requestretry 模块,该模块允许您指定请求的最大尝试重试次数和重试延迟。为了测试这一点,我需要使用 nock 模拟前 X 个请求的超时,然后成功响应相同的请求。我知道有 'socketDelay()' 方法可以延迟连接,但是在第一次延迟响应之后如何指定成功响应?
我有这个,它模拟第一个请求的超时
//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');
【问题讨论】:
标签: javascript node.js nock