我正在为我的node js应用程序编写测试
mocha
在我的测试中,我模拟了1个函数(它正在调用http url),在某些情况下,我添加了1秒睡眠。
由于摩卡测试中的睡眠功能,我的异常率低于零。在实际应用中效果良好。
错误:异步挂钩堆栈已损坏(实际:18,预期:
19)1:V8::SnapshotCreator::默认构造函数闭包2:
节点::调用范围::~调用范围3:
节点::callbackscope::~callbackscope 4:rand_query_egd_bytes 5:
rand_query_egd_bytes 6:uv_timer_get_repeat 7:uv_run 8:
000007FEF8771261 9:000007FEF87710B6 10:
V8::内部::WASM::签名映射::查找11:
V8::内部::内置::可调用12:
V8::内部::内置::可调用13:
V8::内部::内置::可调用14:000002E6363043C1
下面是我的代码
moched函数
.
somefunction() //In Mock test
{
let current_time = Math.round((new Date()).getTime() / 1000);
if (last_execution_time == current_time) {
admin_delete_user_count++;
if (admin_delete_user_count >= 3) {
callback({
stack: "TooManyRequestsException: Rate exceeded",
"code": "TooManyRequestsException",
"statusCode": 400
}, undefined);
return;
}
} else {
admin_delete_user_count = 0;
last_execution_time = Math.round((new Date()).getTime() / 1000);
}
callback(undefined, "Test");
}
下面是我的node js应用程序中的实际函数,它在我从上面的代码发送异常后导致了问题。
somefunction() // In Real applicatio
{
if (err) {
if (err.code == "TooManyRequestsException") {
logger.log("INFO", "TooManyRequestsException, So wait a while for 1 second and retry");
index = index - 1;
sleep(1000); // THIS IS CAUSING THE ISSUE
}
} else {
console.log("deletedUsers:" + JSON.stringify(deletedUsers));
}
}
有什么帮助吗?