Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017Qxbkp4tA7G5SCWjzWuxmE
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { InMemoryKVDriver } from '../../src/kv/memory.js'
|
|
import { runKVDriverConformance } from '../../src/testing/kv-conformance.js'
|
|
import { CountingDriver, MinimalDriver } from '../helpers.js'
|
|
|
|
runKVDriverConformance('InMemoryKVDriver', () => new InMemoryKVDriver())
|
|
runKVDriverConformance('BaseKVDriver (minimal)', () => new MinimalDriver())
|
|
runKVDriverConformance('CountingDriver(InMemory)', () => new CountingDriver())
|
|
|
|
describe('InMemoryKVDriver', () => {
|
|
it('keeps order after large bulk merges', async () => {
|
|
const d = new InMemoryKVDriver()
|
|
const keys = Array.from({ length: 5000 }, (_, i) => `k${(i * 7919) % 5000}`)
|
|
await d.setMany(keys.slice(0, 2500).map((k) => [k, 1]))
|
|
await d.setMany(keys.slice(2500).map((k) => [k, 2]))
|
|
const seen: string[] = []
|
|
for await (const [k] of d.scan({})) seen.push(k)
|
|
expect(seen).toEqual([...new Set(keys)].sort())
|
|
expect(d.size).toBe(5000)
|
|
})
|
|
|
|
it('can skip cloning', async () => {
|
|
const d = new InMemoryKVDriver({ clone: false })
|
|
const v = { n: 1 }
|
|
await d.setMany([['k', v]])
|
|
expect((await d.getMany(['k']))[0]).toBe(v)
|
|
})
|
|
})
|