44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
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() {
|
|
console.log()
|
|
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) {
|
|
process.stdout.write(data)
|
|
if (data.toString().indexOf('secondary') >= 0) res()
|
|
})
|
|
})
|
|
|
|
return kill(worker.pid).then(function(pids) {
|
|
console.log(pids)
|
|
assert.strictEqual(pids.size, 2)
|
|
})
|
|
})
|
|
})
|