Files
usenet-indexer/tests/functional/settler.spec.ts
T
Daan MeijerandClaude Opus 5.5 cdc1cdc0cc
Test and deploy / test (push) Successful in 48s
Test and deploy / edge (push) Successful in 1m59s
Test and deploy / deploy (push) Failing after 4m2s
Prober: claim only candidates of settled releases, without the join
The settler marks a settled release's candidates ready (and unreadable when
it had no readable name). Claims took the candidates by joining releases
from random points of the queue; in its newer half nothing had settled, so
a slice scanned to the end (0.3 s each, 20 slices and 5 tiers a claim) and
the prober stood still: 2.4M waiting, 0 probed a minute. Now an index over
the claimable rows only, the slices drawn within them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 12:12:59 +02:00

40 lines
2.6 KiB
TypeScript

import { test } from '@japa/runner'
import db from '@adonisjs/lucid/services/db'
import testUtils from '@adonisjs/core/services/test_utils'
import Settler from '#services/settler'
test.group('Settler', (group) => {
group.each.setup(() => testUtils.db().withGlobalTransaction())
test('settles quiet releases: complete by the [i/N] counter, unknown without one', async ({ assert }) => {
const old = new Date(Date.now() - 7 * 3600 * 1000)
const row = (key: string, files: number, fileTotal: number | null, lastSeen: Date) => ({
release_key: key.padEnd(40, '0'), identity_key: key.padEnd(40, '0'), name: key, source: 'subject', groups: '[]', files, file_total: fileTotal, last_seen_at: lastSeen,
})
await db.table('releases').multiInsert([row('a', 10, 10, old), row('b', 8, 10, old), row('c', 3, null, old), row('d', 10, 10, new Date())])
assert.equal(await Settler.run(), 3)
const byName = Object.fromEntries((await db.from('releases').select('name', 'complete', 'settled_at')).map((r) => [r.name, [r.complete, r.settled_at !== null]]))
assert.deepEqual(byName, { a: [true, true], b: [false, true], c: [null, true], d: [null, false] })
})
test('settles history releases (posted long ago) once unchanged for half an hour', async ({ assert }) => {
const posted = new Date('2015-01-01T00:00:00Z')
const row = (key: string, lastSeen: Date, lastPosted: Date) => ({
release_key: key.padEnd(40, '0'), identity_key: key.padEnd(40, '0'), name: key, source: 'subject', groups: '[]', files: 1, last_seen_at: lastSeen, posted_at: lastPosted, last_posted_at: lastPosted,
})
const minutesAgo = (m: number) => new Date(Date.now() - m * 60_000)
await db.table('releases').multiInsert([row('old', minutesAgo(31), posted), row('fresh', minutesAgo(5), posted), row('tail', minutesAgo(31), minutesAgo(40))])
const ids = Object.fromEntries((await db.from('releases').select('id', 'name')).map((r) => [r.name, r.id]))
await db.table('probe_candidates').multiInsert([
{ release_id: ids.old, kind: 'lone', message_id: '<a@x>', file: 'a' },
{ release_id: ids.fresh, kind: 'lone', message_id: '<b@x>', file: 'b' },
])
assert.equal(await Settler.run(), 1)
// The settled release's candidates are claimable now, as unreadable (readable defaults to false).
const ready = await db.from('probe_candidates').orderBy('message_id').select('ready', 'unreadable')
assert.deepEqual(ready.map((r) => [r.ready, r.unreadable]), [[true, true], [false, false]])
const settled = (await db.from('releases').whereNotNull('settled_at').select('name')).map((r) => r.name)
assert.deepEqual(settled, ['old'])
})
})