Skip to content

Commit

Permalink
chore: Improving test performance (this code triggered teh 17s indexe…
Browse files Browse the repository at this point in the history
…r delay much more!)
  • Loading branch information
robdmoore committed Mar 25, 2024
1 parent c373221 commit 0ec7735
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions tests/filterFixture.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
import { AlgorandFixtureConfig } from '@algorandfoundation/algokit-utils/types/testing'
import { SendAtomicTransactionComposerResults, SendTransactionResult } from '@algorandfoundation/algokit-utils/types/transaction'
import { Account, Indexer } from 'algosdk'
import { Account } from 'algosdk'
import { expect, vitest } from 'vitest'
import { Arc28EventGroup, TransactionFilter } from '../src/types'
import { GetSubscribedTransactions, SendXTransactions } from './transactions'

export async function waitForIndexerToIndexRound(round: number, indexer: Indexer): Promise<void> {
let caughtUp = false
let tries = 0
while (!caughtUp) {
const status = await indexer.makeHealthCheck().do()
if (Number(status.round) >= round) {
caughtUp = true
} else {
tries++
if (tries > 20) {
throw new Error(`Indexer did not catch up to round ${round} within 20s; received round ${2} instead`)
}
await new Promise<void>((resolve) => setTimeout(resolve, 1000))
}
}
}

export function filterFixture(fixtureConfig?: AlgorandFixtureConfig) {
const localnet = algorandFixture(fixtureConfig)
let systemAccount: Account
Expand All @@ -46,10 +29,9 @@ export function filterFixture(fixtureConfig?: AlgorandFixtureConfig) {
const subscribeIndexer = async (filter: TransactionFilter, result: SendTransactionResult, arc28Events?: Arc28EventGroup[]) => {
const start = +new Date()
// Ensure there is another transaction so algod subscription can process something
const { txIds } = await SendXTransactions(1, systemAccount, localnet.context.algod)
await SendXTransactions(2, systemAccount, localnet.context.algod)
// Wait for indexer to catch up
//await localnet.context.waitForIndexerTransaction(txIds[0])
await waitForIndexerToIndexRound(Number(result.confirmation!.confirmedRound), localnet.context.indexer)
await localnet.context.waitForIndexerTransaction(result.transaction.txID())
const durationInSeconds = (+new Date() - start) / 1000
// eslint-disable-next-line no-console
console.debug(`Prepared for subscribing to indexer in ${durationInSeconds} seconds`)
Expand Down

0 comments on commit 0ec7735

Please sign in to comment.