Fix monitor tests to count only monitor threads

The monitor tests no longer fail if the last step happens to have run a
non-monitor thread in addition to the monitor threads.
This commit is contained in:
Christopher Willis-Ford 2018-11-19 16:34:30 -08:00
parent e071cf3c0c
commit 3649c15f2a
2 changed files with 13 additions and 3 deletions

View file

@ -17,7 +17,12 @@ test('importing sb2 project with monitors', t => {
// All monitors should create threads that finish during the step and // All monitors should create threads that finish during the step and
// are revoved from runtime.threads. // are revoved from runtime.threads.
t.equal(threads.length, 0); t.equal(threads.length, 0);
t.equal(vm.runtime._lastStepDoneThreads.length, 8);
// we care that the last step updated the right number of monitors
// we don't care whether the last step ran other threads or not
const lastStepUpdatedMonitorThreads = vm.runtime._lastStepDoneThreads.filter(thread => thread.updateMonitor);
t.equal(lastStepUpdatedMonitorThreads.length, 8);
// There should be one additional hidden monitor that is in the monitorState but // There should be one additional hidden monitor that is in the monitorState but
// does not start a thread. // does not start a thread.
t.equal(vm.runtime._monitorState.size, 9); t.equal(vm.runtime._monitorState.size, 9);

View file

@ -8,7 +8,7 @@ const Variable = require('../../src/engine/variable');
const projectUri = path.resolve(__dirname, '../fixtures/monitors.sb3'); const projectUri = path.resolve(__dirname, '../fixtures/monitors.sb3');
const project = readFileToBuffer(projectUri); const project = readFileToBuffer(projectUri);
test('importing sb2 project with monitors', t => { test('importing sb3 project with monitors', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();
vm.attachStorage(makeTestStorage()); vm.attachStorage(makeTestStorage());
@ -18,7 +18,12 @@ test('importing sb2 project with monitors', t => {
// All monitors should create threads that finish during the step and // All monitors should create threads that finish during the step and
// are revoved from runtime.threads. // are revoved from runtime.threads.
t.equal(threads.length, 0); t.equal(threads.length, 0);
t.equal(vm.runtime._lastStepDoneThreads.length, 17);
// we care that the last step updated the right number of monitors
// we don't care whether the last step ran other threads or not
const lastStepUpdatedMonitorThreads = vm.runtime._lastStepDoneThreads.filter(thread => thread.updateMonitor);
t.equal(lastStepUpdatedMonitorThreads.length, 17);
// There should be one additional hidden monitor that is in the monitorState but // There should be one additional hidden monitor that is in the monitorState but
// does not start a thread. // does not start a thread.
t.equal(vm.runtime._monitorState.size, 18); t.equal(vm.runtime._monitorState.size, 18);