implemented a lot of features
This commit is contained in:
1 parent
62f1767df3
commit
bcb9be5da9
141 files changed
+10705
-385
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import { test } from '@japa/runner'
|
||||
import db from '@adonisjs/lucid/services/db'
|
||||
import testUtils from '@adonisjs/core/services/test_utils'
|
||||
import FetchRangeService from '#services/FetchRangeService'
|
||||
|
||||
async function groupWithRanges(ranges: [number, number, string][]) {
|
||||
const now = new Date()
|
||||
const [group] = await db
|
||||
.table('groups')
|
||||
.insert({ name: `test.ranges.${Date.now()}`, active: false, last_indexed_id: 100, last_queued_id: 700, created_at: now, updated_at: now })
|
||||
.returning(['id', 'name'])
|
||||
for (const [start, end, status] of ranges) {
|
||||
await db.table('fetch_ranges').insert({ group_id: group.id, start_id: start, end_id: end, status, created_at: now, updated_at: now })
|
||||
}
|
||||
return { id: Number(group.id), name: group.name }
|
||||
}
|
||||
|
||||
test.group('FetchRangeService.advanceWatermark', (group) => {
|
||||
group.each.setup(() => testUtils.db().withGlobalTransaction())
|
||||
|
||||
test('stops just below the first range that is not done', async ({ assert }) => {
|
||||
const g = await groupWithRanges([
|
||||
[101, 200, 'done'],
|
||||
[201, 300, 'failed'],
|
||||
[301, 400, 'done'],
|
||||
[401, 700, 'queued'],
|
||||
])
|
||||
assert.equal(await FetchRangeService.advanceWatermark(g), 200n)
|
||||
// done ranges are forgotten, the gap and the queued range stay
|
||||
const left = await db.from('fetch_ranges').where('group_id', g.id).orderBy('start_id').select('status')
|
||||
assert.deepEqual(left.map((r) => r.status), ['failed', 'queued'])
|
||||
})
|
||||
|
||||
test('reaches the queue cursor when everything is done', async ({ assert }) => {
|
||||
const g = await groupWithRanges([
|
||||
[101, 400, 'done'],
|
||||
[401, 700, 'done'],
|
||||
])
|
||||
assert.equal(await FetchRangeService.advanceWatermark(g), 700n)
|
||||
})
|
||||
|
||||
test('never moves backwards', async ({ assert }) => {
|
||||
const g = await groupWithRanges([[50, 60, 'failed']])
|
||||
assert.equal(await FetchRangeService.advanceWatermark(g), 100n)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user