Files
usenet-indexer/tests/functional/settler.spec.ts
T
Daan MeijerandClaude Opus 5.5 80c920f678
Test and deploy / test (push) Successful in 21s
Test and deploy / deploy (push) Skipped
Rebuild: settling quiet releases
Hourly in coordinator:run: a release unchanged for 6 hours is settled,
complete when every file its [i/N] counter announced was found, unknown
without a counter (phase 2 reads par2 sets for those). Partial index on
unsettled releases.

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

20 lines
1.1 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'), 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] })
})
})