Skip to content

Commit

Permalink
Fix: Fix indexer sync issue in cucumber tests (algorand#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos authored Feb 27, 2024
1 parent cece762 commit f2cc4c6
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/test/java/com/algorand/algosdk/integration/Applications.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Applications {

public Transaction transaction;
public String txId = null;
public Long lastTxConfirmedRound = 0L;
public Long appId = 0L;
public List<Long> rememberedAppIds = new ArrayList<>();

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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<HealthCheck> 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);
}
}
}
}

0 comments on commit f2cc4c6

Please sign in to comment.