2024-03-01 09:39:59 +00:00
|
|
|
import { spawn } from 'child_process'
|
2023-10-31 13:25:08 +00:00
|
|
|
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) {
|
2024-03-01 09:39:59 +00:00
|
|
|
worker = spawn('node', ['./test/kill/runner.mjs'])
|
2023-10-31 13:25:08 +00:00
|
|
|
assert.ok(worker.pid)
|
|
|
|
|
|
|
|
worker.on('exit', done.finish(function(code, signal) {
|
|
|
|
assert.ok(code || signal)
|
|
|
|
}))
|
|
|
|
|
|
|
|
kill(worker.pid)
|
|
|
|
})
|
2024-03-01 09:39:59 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
2023-10-31 13:25:08 +00:00
|
|
|
})
|