tracker
All repositories: gitoria
3.1 KB
// tests/tmdbcheck.mjs — tools/tmdb-check.hl against a tiny fake TMDB (mission 039, tracker#36): a dropped connection does not end the// run (asked again at the end, `failed …` line when it still fails), --from N resumes. No real token, no real TMDB.// COPY=/abs/copy/of/storage/mpackdb TOOL=tools/tmdb-check.hl PORT=8700 node tests/tmdbcheck.mjs (COPY: a copy, never live data)import http from 'node:http';import { spawn } from 'node:child_process';const PORT = Number(process.env.PORT || 8700), COPY = process.env.COPY, TOOL = process.env.TOOL || 'tools/tmdb-check.hl';if (!COPY) { console.log('set COPY'); process.exit(2); }let seen = [], dropAlways = null, dropOnce = null, onceDone = false;const server = http.createServer((req, res) => {const m = /^\/3\/(movie|tv)\/(\d+)/.exec(req.url); const id = m && m[2];seen.push(id);if (id === dropAlways || (id === dropOnce && !onceDone && (onceDone = true))) { req.socket.destroy(); return; }res.writeHead(200, { 'content-type': 'application/json' });res.end(JSON.stringify({ id: Number(id), title: 'x', name: 'x', original_title: 'x', original_name: 'x', release_date: '1999-01-01', first_air_date: '1999-01-01' }));});await new Promise(r => server.listen(PORT, '127.0.0.1', r));const run = (args) => new Promise((resolve) => {seen = []; onceDone = false; let out = '';const p = spawn('./bin/hybriel', [TOOL, ...args], { env: { ...process.env, TMDB_READ_TOKEN: 'fake-token', TMDB_BASE_URL: `http://127.0.0.1:${PORT}/3`, TRACKER_STORAGE: COPY } });p.stdout.on('data', d => out += d); p.stderr.on('data', d => out += d);p.on('close', code => resolve({ code, out, seen: [...seen] }));});let pass = 0, fail = 0;const check = (name, ok, extra = '') => { ok ? pass++ : fail++; console.log((ok ? 'PASS ' : 'FAIL ') + name + (ok ? '' : ' — ' + extra)); };const base = await run(['--limit', '6', '--all']);const ids = base.seen;check('baseline: 6 asked, exit 0', ids.length == 6 && base.code == 0, base.out.slice(-300));dropAlways = ids[1]; dropOnce = ids[2];const r1 = await run(['--limit', '6', '--all']);const cnt = (id) => r1.seen.filter(x => x === id).length;check('run goes on after dropped connections (exit 0, done line)', r1.code == 0 && /tmdb check done: asked=6/.test(r1.out), r1.out.slice(-400));check('dropped-once title asked again, then ok', cnt(ids[2]) == 2 && cnt(ids[1]) == 2 && ids.slice(3).every(i => cnt(i) == 1), JSON.stringify(r1.seen));const failedLines = r1.out.split('\n').filter(l => l.startsWith('failed '));check('exactly one `failed` line, with the reason, for the title that kept failing', failedLines.length == 1 && failedLines[0].includes('tmdb ' + ids[1] + ':') && /no answer/.test(failedLines[0]), r1.out);check('totals: clear=5 failed=1 retried=2', /clear=5 errors=0 failed=1 retried=2/.test(r1.out), r1.out.slice(-300));dropAlways = null;const r2 = await run(['--from', '4', '--limit', '2']);check('--from 4 --limit 2 asks exactly titles 5 and 6 of the same order', JSON.stringify(r2.seen) == JSON.stringify(ids.slice(4, 6)), JSON.stringify(r2.seen));server.close(); console.log(`tmdbcheck: ${pass} pass, ${fail} fail`); process.exit(fail ? 1 : 0);
Branches
Latest commits
- bfc4ea4dMerge branch 'ap62' into mainTracker
- 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
- b9c7c3c8Merge branch 'records-dp74' into mainTracker
- 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
- b1496147Merge branch 'ap61' into mainTracker
- 2047955bMerge branch 'u12-gateports' into mainTracker
- c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker
- 4e018678|||PR deploy.sh: gates use Tracker's ports 8716-8719 and LC_ALL=C; README: 2 backups keptTracker
- 0b86324aMerge branch 'records-dp73' into mainTracker
- 9ce5f59b|||PR records: DP73 live 613ae0e; deploy.sh keeps 2 backupsTracker
- 613ae0ecMerge branch 'bs3' into mainTracker
- 1383264b|||PR BS3: keep shared synchronous sorting fastTracker
- 63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker
- 310613f1Merge branch 'records-dp72' into mainTracker
- 6f7b61ba|||PR records: deploy-swap fix live, Kunibert findingsTracker
- c41587d2Merge branch 'bs2' into mainTracker
- 0dd538a6|||PR BS2: finish the boot index in slices so a booting instance keeps answeringTracker
- 019d5cedMerge branch 'records-1110' into mainTracker
- f88ae8b9|||PR records: day56 toggle live, reviewTracker
- b6b3bb4dMerge branch 'ap56e' into mainTracker