pokemon-showdown/test/application/process-manager.js
Ben Davies d9c6fe54b2 ProcessManager: subclass to extend ProcessManager, unit tests setup (#2739)
Before, an options object containing properties and values to be used
was how decorated instances of the class would be created. This meant
the constructor could assign anything you feel like to `this`. Rather
than that, the constructor now assigns a strict set of values, and
methods are redefined in subclasses.

Basic unit tests were added to test if they could be written for after
the final refactor to fix the other memory leak here.
2016-09-09 15:51:49 -05:00

62 lines
1.9 KiB
JavaScript

'use strict';
const assert = require('assert');
const path = require('path');
const ProcessManager = require('../../process-manager');
const ProcessWrapper = ProcessManager.ProcessWrapper;
// const DatasearchManager = require('../../chat-plugins/datasearch.js').DatasearchManager;
// const SimulatorManager = require('../../simulator.js').SimulatorManager;
// const TeamValidatorManager = require('../../team-validator.js').TeamValidatorManager;
// const VerifierManager = require('../../verifier.js').VerifierManager;
// DO NOT CLEAR PROCESSMANAGER'S CACHE DURING THESE TESTS
// Delete the ProcessManager instances from it manually unless you want to break
// other tests that rely on what's already there at the beginning of these tests
// and watch the world burn.
describe('ProcessManager', function () {
it('should construct', function () {
let pm;
let cacheSize = ProcessManager.cache.size;
assert.doesNotThrow(() => {
pm = new ProcessManager({
execFile: path.resolve('./process-manager'),
maxProcesses: 0,
isChatBased: false,
});
});
assert.strictEqual(ProcessManager.cache.size, cacheSize + 1);
assert.ok(ProcessManager.cache.delete(pm));
});
describe('ProcessWrapper', function () {
beforeEach(function () {
this.pm = new ProcessManager({
execFile: path.resolve('./process-manager'),
maxProcesses: 0,
isChatBased: false,
});
});
afterEach(function () {
// Temporary until final process-manager.js refactor
this.pm.processes.forEach(pw => {
pw.process.removeAllListeners('message');
pw.process.disconnect();
pw.process = null;
pw.removeAllListeners('message');
pw.pendingTasks.clear();
pw.PM.processes.splice(pw.PM.processes.indexOf(pw), 1);
pw.PM = null;
});
ProcessManager.cache.delete(this.pm);
});
it('should construct', function () {
assert.doesNotThrow(() => new ProcessWrapper(this.pm));
});
});
});