From f2cc4c6a1a2b1981a2a039ce2b1156806d2d535a Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Tue, 27 Feb 2024 16:42:10 -0500 Subject: [PATCH] Fix: Fix indexer sync issue in cucumber tests (#686) --- .../algosdk/integration/Applications.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/algorand/algosdk/integration/Applications.java b/src/test/java/com/algorand/algosdk/integration/Applications.java index 85d7758ee..1e58d5428 100644 --- a/src/test/java/com/algorand/algosdk/integration/Applications.java +++ b/src/test/java/com/algorand/algosdk/integration/Applications.java @@ -36,6 +36,7 @@ public class Applications { public Transaction transaction; public String txId = null; + public Long lastTxConfirmedRound = 0L; public Long appId = 0L; public List rememberedAppIds = new ArrayList<>(); @@ -141,7 +142,8 @@ public void sendTransactionWithTransientAccountAndCheckForError(String error) th @Given("I wait for the transaction to be confirmed.") public void waitForTransactionToBeConfirmed() throws Exception { - Utils.waitForConfirmation(base.aclv2, base.txid, 1); + PendingTransactionResponse response = Utils.waitForConfirmation(base.aclv2, base.txid, 1); + this.lastTxConfirmedRound = response.confirmedRound; } @Given("I remember the new application ID.") @@ -346,8 +348,30 @@ public void indexerCheckAppBoxesWithParams(Long limit, String next, String encod assertSetOfByteArraysEqual(expectedNames, actualNames); } - @Then("I sleep for {int} milliseconds for indexer to digest things down.") - public void sleepForNSecondsForIndexer(int milliseconds) throws Exception { - Thread.sleep(milliseconds); + @Then("I wait for indexer to catch up to the round where my most recent transaction was confirmed.") + public void sleepForNSecondsForIndexer() throws Exception { + final int maxAttempts = 30; + + final long roundToWaitFor = this.lastTxConfirmedRound; + long indexerRound = 0; + int attempts = 0; + + while(true) { + Response response = base.v2IndexerClient.makeHealthCheck().execute(); + Assert.assertTrue(response.isSuccessful()); + indexerRound = response.body().round; + if (indexerRound >= roundToWaitFor) { + // Success + break; + } + + // Sleep for 1 second and try again + Thread.sleep(1000); + attempts++; + + if (attempts > maxAttempts) { + throw new Exception("Timeout waiting for indexer to catch up to round " + roundToWaitFor + ". It is currently on " + indexerRound); + } + } } }