Something went wrong. Try again.
Hardware-in-the-loop development platform for the Commodore 64.
Something went wrong. Try again.
2.4 kB · 49 lines
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950'use strict';
const { test, expect } = require('@playwright/test');const { spawn } = require('node:child_process');const fs = require('node:fs/promises');const { withTimeout } = require('./server.cjs');
test('parent interruption stops fixture and production children before directory cleanup', async () => { test.setTimeout(120_000); const fixtureModule = require.resolve('./server.cjs'); const productionModule = require.resolve('./production.cjs'); const script = ` const {startFixtureServer} = require(${JSON.stringify(fixtureModule)}); const {startProductionServer} = require(${JSON.stringify(productionModule)}); (async () => { const fixture = await startFixtureServer(); const production = await startProductionServer(require('node:path').join(fixture.directory, 'c64dev.toml')); console.log('INTERRUPT_READY ' + JSON.stringify({directory:fixture.directory,fixturePid:fixture.pid,productionPid:production.pid,urls:[fixture.url,production.url]})); })().catch(error => { console.error(error); process.exit(1); }); `; const child = spawn(process.execPath, ['-e', script], { stdio: ['ignore', 'pipe', 'pipe'] }); let log = ''; const exit = new Promise(resolve => child.once('close', resolve)); try { const state = await withTimeout(new Promise((resolve, reject) => { child.stdout.on('data', chunk => { log = (log + chunk.toString()).slice(-16000); const match = log.match(/INTERRUPT_READY (\{[^\n]+\})/); if (match) resolve(JSON.parse(match[1])); }); child.stderr.on('data', chunk => { log += chunk.toString(); }); exit.then(() => reject(new Error(`Disposable parent exited: ${log.slice(-3000)}`))); }), 100_000, 'Disposable parent readiness timed out'); child.kill('SIGTERM'); await withTimeout(exit, 12_000, 'Disposable parent did not finish signal cleanup'); for (const pid of [state.fixturePid, state.productionPid]) { expect(() => process.kill(-pid, 0)).toThrow(); } await expect(fs.stat(state.directory)).rejects.toMatchObject({code:'ENOENT'}); for (const url of state.urls) { await expect(fetch(`${url}/api/v1/health`, {signal:AbortSignal.timeout(1000)})).rejects.toThrow(); } } finally { if (child.exitCode === null) { child.kill('SIGTERM'); await withTimeout(exit, 12_000, 'Disposable parent cleanup failed'); } }});