TheThing
15d1ba43f4
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
41 lines
1,008 B
JavaScript
41 lines
1,008 B
JavaScript
import { spawn } from 'child_process'
|
|
import t from '../../lib/eltro.mjs'
|
|
import assert from '../../lib/assert.mjs'
|
|
import kill from '../../lib/kill.mjs'
|
|
|
|
t.describe('kill', function() {
|
|
let worker
|
|
|
|
t.afterEach(function() {
|
|
if (worker?.pid && !worker.killed) {
|
|
worker.kill()
|
|
}
|
|
})
|
|
|
|
t.test('should kill process correctly', function(done) {
|
|
worker = spawn('node', ['./test/kill/runner.mjs'])
|
|
assert.ok(worker.pid)
|
|
|
|
worker.on('exit', done.finish(function(code, signal) {
|
|
assert.ok(code || signal)
|
|
}))
|
|
|
|
kill(worker.pid)
|
|
})
|
|
|
|
t.test('should succeed in killing tree', async function() {
|
|
worker = spawn('node', ['./test/kill/runner.mjs'])
|
|
assert.ok(worker.pid)
|
|
|
|
// Give it some time to start
|
|
await new Promise(res => {
|
|
worker.stdout.on('data', function(data) {
|
|
if (data.toString().indexOf('secondary') >= 0) res()
|
|
})
|
|
})
|
|
|
|
return kill(worker.pid).then(function(pids) {
|
|
assert.strictEqual(pids.size, 2)
|
|
})
|
|
})
|
|
})
|