mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-02 06:29:57 +08:00
* feat(device-link): 加速跨端文件与附件传输并提供自动验收 Signed-off-by: Dash <dash@DashdeMac-Studio.local> * test(device-link): 补齐 IPC 与 WebView 生命周期验收 Signed-off-by: Dash <dash@DashdeMac-Studio.local> * fix(device-link): 隔离读取失败并修复附件过期与重试路径 Signed-off-by: Dash <dash@DashdeMac-Studio.local> --------- Signed-off-by: Dash <dash@DashdeMac-Studio.local> Co-authored-by: Dash <dash@DashdeMac-Studio.local>
31 lines
1.4 KiB
JavaScript
31 lines
1.4 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { spawn } from 'node:child_process';
|
|
import { once } from 'node:events';
|
|
import { terminateTestProcess } from '../shared/terminate-test-process.mjs';
|
|
|
|
test('kills a test probe and its detached browser-like descendant', { timeout: 10_000 }, async () => {
|
|
const probe = spawn(process.execPath, ['-e', `
|
|
const { spawn } = require('node:child_process');
|
|
const descendant = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { detached: true, stdio: 'ignore' });
|
|
console.log(descendant.pid);
|
|
setInterval(() => {}, 1000);
|
|
`], { stdio: ['ignore', 'pipe', 'ignore'] });
|
|
let descendant;
|
|
try {
|
|
const [data] = await once(probe.stdout, 'data');
|
|
descendant = Number(String(data).trim());
|
|
assert.ok(Number.isSafeInteger(descendant) && descendant > 0);
|
|
const closed = once(probe, 'close');
|
|
terminateTestProcess(probe);
|
|
await closed;
|
|
const running = () => { try { process.kill(descendant, 0); return true; } catch { return false; } };
|
|
for (let i = 0; i < 100 && running(); i++) await new Promise(resolve => setTimeout(resolve, 20));
|
|
assert.equal(running(), false);
|
|
terminateTestProcess(probe); // Settled children cannot target a reused PID.
|
|
} finally {
|
|
if (descendant) { try { process.kill(descendant, 'SIGKILL'); } catch {} }
|
|
if (probe.exitCode === null && probe.signalCode === null) probe.kill('SIGKILL');
|
|
}
|
|
});
|