Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

KeyScheduler-lifecycle.test.ts

30 lines1.3 KB

1// Ordinary unit tests for KeyScheduler's selective removal of unissued work. The
2// generated lifecycle law is owned by KeyScheduler-oracle.property.test.ts
3// (offline.key-scheduler-fifo-ledger).
4import { describe, expect, it } from 'vitest'
5import { KeyScheduler } from '../src/executor/KeyScheduler'
6import { BASE_TIME, createTransaction } from './key-scheduler-support'
7​
8describe(`KeyScheduler generated lifecycle`, () => {
9 it(`selectively removes only unissued work`, () => {
10 const scheduler = new KeyScheduler()
11 const active = createTransaction(``, BASE_TIME, BASE_TIME, 1)
12 const removed = createTransaction(`removed`, BASE_TIME + 1, BASE_TIME, 2)
13 const retained = createTransaction(`retained`, BASE_TIME + 2, BASE_TIME, 3)
14 scheduler.schedule(active)
15 scheduler.schedule(removed)
16 scheduler.schedule(retained)
17 scheduler.markStarted(active)
18​
19 expect(
20 scheduler.removePendingTransactions([active.id, removed.id, `missing`]),
21 ).toEqual([removed.id, `missing`])
22​
23 expect({
24 pending: scheduler.getAllPendingTransactions().map(({ id }) => id),
25 running: scheduler.getRunningCount(),
26 }).toEqual({ pending: [active.id, retained.id], running: 1 })
27 scheduler.markCompleted(active)
28 expect(scheduler.getNext()?.id).toBe(retained.id)
29 })
30})