Fix a race in the cancel_command test #82
@@ -126,7 +126,9 @@ describe('cancel_command (#8)', () => {
|
|||||||
test('cancelling stops the command and everything it started', async () => {
|
test('cancelling stops the command and everything it started', async () => {
|
||||||
const w = makeWorker();
|
const w = makeWorker();
|
||||||
const pidFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'pulse-cancel-')), 'pid');
|
const pidFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'pulse-cancel-')), 'pid');
|
||||||
const pending = w.executeCommand({ command: `sleep 30 & echo $! > ${pidFile}; wait`, execution_id: 'ex-c', command_id: 'cmd-c' });
|
// Write then rename: the shell creates a redirect target before writing to it,
|
||||||
|
// so reading ${pidFile} directly could see an empty file (pid 0).
|
||||||
|
const pending = w.executeCommand({ command: `sleep 30 & echo $! > ${pidFile}.tmp && mv ${pidFile}.tmp ${pidFile}; wait`, execution_id: 'ex-c', command_id: 'cmd-c' });
|
||||||
for (let i = 0; i < 50 && !fs.existsSync(pidFile); i++) await new Promise(r => setTimeout(r, 50));
|
for (let i = 0; i < 50 && !fs.existsSync(pidFile); i++) await new Promise(r => setTimeout(r, 50));
|
||||||
const childPid = Number(fs.readFileSync(pidFile, 'utf8'));
|
const childPid = Number(fs.readFileSync(pidFile, 'utf8'));
|
||||||
expect(alive(childPid)).toBe(true);
|
expect(alive(childPid)).toBe(true);
|
||||||
|
|||||||
Reference in new issue
Block a user