test(execute): try to make 'execute' test more reliable

This commit is contained in:
Christopher Willis-Ford 2022-06-07 09:54:08 -07:00
parent 8263893c5b
commit d8fc81a8b5

View file

@ -27,7 +27,7 @@ const VirtualMachine = require('../../src/index');
* been reached.
*/
const whenThreadsComplete = (t, vm, timeLimit = 2000) => (
const whenThreadsComplete = (t, vm, uri, timeLimit = 5000) =>
// When the number of threads reaches 0 the test is expected to be complete.
new Promise((resolve, reject) => {
const intervalId = setInterval(() => {
@ -44,6 +44,7 @@ const whenThreadsComplete = (t, vm, timeLimit = 2000) => (
}, 50);
const timeoutId = setTimeout(() => {
t.fail(`Timeout waiting for threads to complete: ${uri}`);
reject(new Error('time limit reached'));
}, timeLimit);
@ -53,8 +54,7 @@ const whenThreadsComplete = (t, vm, timeLimit = 2000) => (
clearInterval(intervalId);
clearTimeout(timeoutId);
});
})
);
});
const executeDir = path.resolve(__dirname, '../fixtures/execute');
@ -127,7 +127,7 @@ fs.readdirSync(executeDir)
// the scratch project sent us a "end" message.
return vm.loadProject(project)
.then(() => vm.greenFlag())
.then(() => whenThreadsComplete(t, vm))
.then(() => whenThreadsComplete(t, vm, uri))
.then(() => {
// Setting a plan is not required but is a good idea.
if (!didPlan) {