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

shard.test.ts

36 lines1.3 KB

1import { describe, expect, it } from 'vitest'
2​
3import { providerRegistry } from '#/server/providers/index.ts'
4import { SPEC_SYNC_SHARD_CRONS, specSyncShard } from './sync.ts'
5​
6describe('specSyncShard', () => {
7 const shards = SPEC_SYNC_SHARD_CRONS.map((_, i) => specSyncShard(i))
8​
9 it('covers every registered provider exactly once', () => {
10 const assigned = shards.flat().map((p) => p.id)
11 expect(assigned.sort()).toEqual(providerRegistry.map((p) => p.id).sort())
12 expect(new Set(assigned).size).toBe(assigned.length)
13 })
14​
15 it('isolates fal in its own shard', () => {
16 expect(shards[0]?.map((p) => p.id)).toEqual(['fal'])
17 })
18​
19 it('spreads the rest across the remaining shards', () => {
20 const restSizes = shards.slice(1).map((s) => s.length)
21 const rest = providerRegistry.length - 1
22 expect(restSizes.reduce((a, b) => a + b, 0)).toBe(rest)
23 // Round-robin: shard sizes differ by at most one.
24 expect(Math.max(...restSizes) - Math.min(...restSizes)).toBeLessThanOrEqual(
25 1,
26 )
27 })
28​
29 it('keeps the wrangler.jsonc cron list in lockstep', async () => {
30 const fs = await import('node:fs/promises')
31 const raw = await fs.readFile('wrangler.jsonc', 'utf8')
32 for (const cron of SPEC_SYNC_SHARD_CRONS) {
33 expect(raw).toContain(`"${cron}"`)
34 }
35 })
36})