Skip to content

Commit

Permalink
Fix intermittent test failure due to insertion order
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Dec 19, 2024
1 parent 6c71b5e commit df9652d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"--run",
"--inspect-brk",
"--no-file-parallelism",
"packages/modules/packages/diviner/packages/payloadpointer/packages/memory/src/spec/Diviner.payloadPointer.sequence.spec.ts"
"--testTimeout=120000",
"packages/modules/packages/diviner/packages/addresschain/packages/memory/src/spec/MemoryDiviner.spec.ts"
],
"sourceMaps": true,
"resolveSourceMapLocations": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"@xyo-network/payload-model": "workspace:^"
},
"devDependencies": {
"@xylabs/array": "^4.4.25",
"@xylabs/delay": "^4.4.25",
"@xylabs/ts-scripts-yarn3": "^4.2.6",
"@xylabs/tsconfig": "^4.2.6",
"@xylabs/vitest-extended": "^4.4.25",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class MemoryAddressChainDiviner<
const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')
let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')
while (currentHash && result.length < (this.config.maxResults ?? 1000)) {
console.log(`currentHash: ${currentHash}`)
// console.log(`currentHash: ${currentHash}`)
const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)
const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)
if (bwWrapper) {
Expand All @@ -52,7 +52,7 @@ export class MemoryAddressChainDiviner<
}

private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {
console.log('archivistFindHash')
// console.log('archivistFindHash')
let index = 0
if (archivists[index]) {
const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithStorageMeta)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import '@xylabs/vitest-extended'

import { filterAs } from '@xylabs/array'
import { assertEx } from '@xylabs/assert'
import { delay } from '@xylabs/delay'
import { Account } from '@xyo-network/account'
import { MemoryArchivist } from '@xyo-network/archivist-memory'
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
import type { BoundWitness } from '@xyo-network/boundwitness-model'
import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
import { asOptionalBoundWitness, BoundWitnessSchema } from '@xyo-network/boundwitness-model'
import { AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'
import { MemoryNode } from '@xyo-network/node-memory'
import { NodeConfigSchema } from '@xyo-network/node-model'
Expand Down Expand Up @@ -40,14 +43,18 @@ describe('MemoryAddressHistoryDiviner', () => {
const payload2 = PayloadWrapper.wrap({ index: 2, schema: 'network.xyo.test' })
const payload3 = PayloadWrapper.wrap({ index: 3, schema: 'network.xyo.test' })

await archivistWrapper.insert([payload1.payload])
await archivistWrapper.insert([payload2.payload])
await archivistWrapper.insert([payload3.payload])

for (const payload of [payload1, payload2, payload3]) {
await delay(2)
await archivistWrapper.insert([payload.payload])
}
const all = await archivist.all()

expect(all).toBeArrayOfSize(6)

const allBWs = filterAs(all, asOptionalBoundWitness)
const lastBw = allBWs.at(-1)
expect(lastBw).toBeDefined()
const startHash = await PayloadBuilder.dataHash(assertEx(lastBw))

await node.register(archivist)
await node.attach(archivist.address)
const diviner = await MemoryAddressChainDiviner.create({
Expand All @@ -56,7 +63,7 @@ describe('MemoryAddressHistoryDiviner', () => {
address: wrapperAccount.address,
archivist: archivist.address,
schema: AddressChainDivinerConfigSchema,
startHash: (await PayloadBuilder.dataHash(all[5])),
startHash,
},
})
await node.register(diviner)
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6097,7 +6097,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@xyo-network/diviner-address-chain-memory@workspace:packages/modules/packages/diviner/packages/addresschain/packages/memory"
dependencies:
"@xylabs/array": "npm:^4.4.25"
"@xylabs/assert": "npm:^4.4.25"
"@xylabs/delay": "npm:^4.4.25"
"@xylabs/hex": "npm:^4.4.25"
"@xylabs/ts-scripts-yarn3": "npm:^4.2.6"
"@xylabs/tsconfig": "npm:^4.2.6"
Expand Down

0 comments on commit df9652d

Please sign in to comment.