Skip to content

Commit

Permalink
Add test for Archivist insertion order
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Dec 21, 2024
1 parent 486f93f commit d126a8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"--inspect-brk",
"--no-file-parallelism",
"--testTimeout=120000",
"packages/modules/packages/diviner/packages/indexing/packages/temporal/packages/memory/src/StateToIndexCandidateDiviner/spec/Diviner.spec.ts"
"packages/modules/packages/archivist/packages/memory/src/spec/MemoryArchivist.spec.ts"
],
"sourceMaps": true,
"resolveSourceMapLocations": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ describe('MemoryArchivist', () => {
await archivist.clear()
})

it('should return same items inserted in the order they were inserted in', async () => {
it('should return items inserted in the order they were provided in', async () => {
const archivist = await MemoryArchivist.create({ account: 'random' })
const payloads = Array.from({ length: 100 }, (_, i) => new PayloadBuilder<Id>({ schema: IdSchema }).fields({ salt: `${i}` }).build())
const payloads: Id[] = Array.from({ length: 100 }, (_, i) => new PayloadBuilder<Id>({ schema: IdSchema }).fields({ salt: `${i}` }).build())
// Ensure payload was create in order provided
for (const [index, id] of payloads.entries()) {
expect(id?.salt).toBe(`${index}`)
}

const result = await archivist.insert(payloads)
const results = await archivist.insert(payloads)

// Ensure payload was inserted in order provided
for (const [index, payload] of result.entries()) {
expect(isId(payload)).toBe(true)
const id = asId(payload)
for (const [index, result] of results.entries()) {
expect(isId(result)).toBe(true)
const id = asId(result)
expect(id).toBeDefined()
expect(id?.salt).toBe(`${index}`)
expect(await PayloadBuilder.dataHash(payload)).toEqual(await PayloadBuilder.dataHash(payloads[index]))
expect(await PayloadBuilder.dataHash(result)).toEqual(await PayloadBuilder.dataHash(payloads[index]))
}
})

Expand Down

0 comments on commit d126a8e

Please sign in to comment.