#3454·ava

阻塞测试不会导致超时测试失败

作者: ericcornelissen创建于 2026年5月30日更新于 2026年6月6日
标签needs triage

When a test is slow in a blocking fashion, AVA's timeout does not apply. A blocking test can take 10s and pass with a 5s timeout. The following test suite demonstrates the asymmetry between blocking and non-blocking tests (with a 10ms runtime and 5ms timeout instead):

javascript
// minimal-ava.js
var test = require('ava').default;
test('blocking', function (t) {
t.timeout(5);
var start = Date.now();
while (Date.now() < start + 10) { /* Busy-wait to block the event loop */ }
t.pass("slow success");
});
test('async', function (t) {
t.timeout(5);
return new Promise(function (resolve) {
setTimeout(function () {
t.pass("slow success");
resolve();
}, 10);
});
});
If you run it (using an up-to-date version of Node.js and AVA) the first test will pass and the other will fail: