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