GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pdf-parser/integrations/javascript/subprocess.test.mjs at main · Tom-R-Main/pdf-parser

Expand file tree

/

subprocess.test.mjs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (33 loc) · 2.26 KB
/

subprocess.test.mjs

Copy path

File metadata and controls

34 lines (33 loc) · 2.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, writeFile, readFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { setTimeout as delay } from 'node:timers/promises';
import { extractPdfDocument, extractPdfPages } from './index.mjs';
for (const [name, extract] of [['batch', extractPdfDocument], ['stream', extractPdfPages]]) {
test(`${name} cancellation lets nested parents reap descendants before termination`, { skip: process.platform === 'win32' }, async t => {
const directory = await mkdtemp(join(tmpdir(), 'pdf-parser-reaping-'));
t.after(() => rm(directory, { recursive: true, force: true }));
const pids = join(directory, 'pids.json');
const reaped = join(directory, 'reaped.log');
const middle = `const fs=require('node:fs'); const child=require('node:child_process').spawn(process.execPath,['-e','setInterval(()=>{},1000)']);
fs.writeFileSync(${JSON.stringify(pids)},JSON.stringify({middle:process.pid,leaf:child.pid}));
child.on('exit',()=>fs.appendFileSync(${JSON.stringify(reaped)},'leaf-reaped\\n')); setInterval(()=>{},1000);`;
const binaryPath = join(directory, 'parser');
await writeFile(binaryPath, `#!${process.execPath}\nconst fs=require('node:fs');
const child=require('node:child_process').spawn(process.execPath,['-e',${JSON.stringify(middle)}]);
child.on('exit',()=>fs.appendFileSync(${JSON.stringify(reaped)},'middle-reaped\\n')); setInterval(()=>{},1000);\n`, { mode: 0o700 });
const controller = new AbortController();
const operation = extract(Buffer.from('%PDF-test'), { binaryPath, timeoutMs: 5000, signal: controller.signal, onPage() {} });
let audit;
for (let attempt = 0; attempt < 100 && !audit; attempt++) {
try { audit = JSON.parse(await readFile(pids, 'utf8')); } catch (error) { if (error.code !== 'ENOENT') throw error; await delay(20); }
}
assert.ok(audit, 'nested descendant must exist before cancellation');
controller.abort();
await assert.rejects(operation, { code: 'aborted' });
assert.equal(await readFile(reaped, 'utf8'), 'leaf-reaped\nmiddle-reaped\n');
for (const pid of Object.values(audit)) assert.throws(() => process.kill(pid, 0), { code: 'ESRCH' });
});
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.