test(clone-cleanup): improve clone-cleanup test reliability

Previously the test relied on the project's `wait` blocks running at roughly real time. Now, the
project drives the timing using `say` blocks.
This commit is contained in:
Christopher Willis-Ford 2022-06-06 11:56:23 -07:00
parent 05f8692300
commit 605b1c2386
4 changed files with 9 additions and 13 deletions

Binary file not shown.

BIN
test/fixtures/clone-cleanup.sb3 vendored Normal file

Binary file not shown.

View file

@ -4,7 +4,7 @@ const makeTestStorage = require('../fixtures/make-test-storage');
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
const VirtualMachine = require('../../src/index');
const projectUri = path.resolve(__dirname, '../fixtures/clone-cleanup.sb2');
const projectUri = path.resolve(__dirname, '../fixtures/clone-cleanup.sb3');
const project = readFileToBuffer(projectUri);
test('clone-cleanup', t => {
@ -17,12 +17,6 @@ test('clone-cleanup', t => {
*/
let testStep = -1;
/**
* We test using setInterval; track the interval ID here so we can cancel it.
* @type {object}
*/
let testInterval = null;
const verifyCounts = (expectedClones, extraThreads) => {
// stage plus one sprite, plus clones
t.strictEqual(vm.runtime.targets.length, 2 + expectedClones,
@ -60,15 +54,17 @@ test('clone-cleanup', t => {
break;
case 3:
// The second batch of clones has been created and the main thread has ended
verifyCounts(10, 0);
// The second batch of clones has been created and the main thread is about to end
verifyCounts(10, 1);
// After the main thread ends, do one last test step
setTimeout(() => testNextStep(), 1000);
break;
case 4:
// The second batch of clones has deleted themselves; everything is finished
verifyCounts(0, 0);
clearInterval(testInterval);
t.end();
process.nextTick(process.exit);
break;
@ -88,8 +84,8 @@ test('clone-cleanup', t => {
vm.greenFlag();
// Every second, advance the testing step
testInterval = setInterval(testNextStep, 1000);
// Let the project control the pace of the tests
vm.runtime.on('SAY', () => testNextStep());
});
});

View file

@ -4,7 +4,7 @@ const VirtualMachine = require('../../src/index');
const Runtime = require('../../src/engine/runtime');
const sb3 = require('../../src/serialization/sb3');
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
const exampleProjectPath = path.resolve(__dirname, '../fixtures/clone-cleanup.sb2');
const exampleProjectPath = path.resolve(__dirname, '../fixtures/complex.sb2');
const commentsSB2ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb2');
const commentsSB3ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb3');
const commentsSB3NoDupeIds = path.resolve(__dirname, '../fixtures/comments_no_duplicate_id_serialization.sb3');