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
- 074a7418log: #62 assigned to Tracker; pending rulemre
- 06f6ae8fHM62 report: mpackdb index gapmre
- 86fe5430log: HM62 startedmre
- 755307bbmission HM62mre
- 4b2f2995HM61 report: tracker#61 packed people ordermre
- 48faa84flog: #60 deploy startedmre
- 90734c6cMerge branch 'hm60-shortids'mre
- e0db0d1bHM60 report: tracker#60 packed short-ID ownersmre
- 3c79b576Pack short-ID ownership into byte buffersmre
- e822524bstatus wordingmre
- 1c7f0480log: HM60/HM61 startedmre
- 2841d215missions HM60 HM61mre
- 289c6ce4HM1 report: heap object breakdownmre
- 2e7d6257log: HM1 startedmre
- 2f790465mission HM1: heap object breakdownmre
- a18957falog: evening re-measure after CBmre
- aac9a98dlog: evening re-measure startmre
- 45163bd4log: person/tmdb error hypothesismre
- cb38de2blog: swap 503 causemre
- fd10c3d5log: CB livemre