Error: async hook stack has become corrupted in node js
Error: async hook stack has become corrupted in node js
我正在使用 mocha
为我的 Node JS 应用程序编写测试
在我的测试中,我模拟了 1 个函数(调用 HTTP Url)并且在某些情况下,我增加了 1 秒的睡眠时间。
由于 mocha 测试中的睡眠功能,我遇到了异常。在实际应用中它工作正常。
Error: async hook stack has become corrupted (actual: 18, expected:
19) 1: v8::SnapshotCreator::default constructor closure 2:
node::CallbackScope::~CallbackScope 3:
node::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::internal::wasm::SignatureMap::Find 11:
v8::internal::Builtins::CallableFor 12:
v8::internal::Builtins::CallableFor 13:
v8::internal::Builtins::CallableFor 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");
}
下面是我的节点 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));
}
}
有什么帮助吗?
我发现了上面列出的问题。
基本上有 250 毫秒的超时,这导致了异步挂钩生命周期中的问题。
我从
timeout.timeout('waitTimer', 250,
function() {
expect(res.statusCode).to.equal(200);
done();
}
);
到
timeout.timeout('waitTimer', 1250,
function() {
expect(res.statusCode).to.equal(200);
done();
}
);
谢谢!
我正在使用 mocha
为我的 Node JS 应用程序编写测试在我的测试中,我模拟了 1 个函数(调用 HTTP Url)并且在某些情况下,我增加了 1 秒的睡眠时间。
由于 mocha 测试中的睡眠功能,我遇到了异常。在实际应用中它工作正常。
Error: async hook stack has become corrupted (actual: 18, expected: 19) 1: v8::SnapshotCreator::default constructor closure 2:
node::CallbackScope::~CallbackScope 3:
node::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::internal::wasm::SignatureMap::Find 11:
v8::internal::Builtins::CallableFor 12:
v8::internal::Builtins::CallableFor 13:
v8::internal::Builtins::CallableFor 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");
}
下面是我的节点 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));
}
}
有什么帮助吗?
我发现了上面列出的问题。
基本上有 250 毫秒的超时,这导致了异步挂钩生命周期中的问题。
我从
timeout.timeout('waitTimer', 250,
function() {
expect(res.statusCode).to.equal(200);
done();
}
);
到
timeout.timeout('waitTimer', 1250,
function() {
expect(res.statusCode).to.equal(200);
done();
}
);
谢谢!