Skip to content

Commit b2fdcf3

Browse files
committed
test: wait for indexer health before proof calls (fix flaky test-validator races)
1 parent dfdbb09 commit b2fdcf3

18 files changed

Lines changed: 180 additions & 18 deletions

File tree

account-comparison/programs/account-comparison/tests/test_compressed_account.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ async fn start_validator_and_connect() -> LightClient {
5454
tokio::time::sleep(Duration::from_secs(1)).await;
5555
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5656
}
57-
tokio::time::sleep(Duration::from_secs(10)).await;
57+
58+
// Wait for the indexer + prover to be ready (not just the validator RPC),
59+
// otherwise proof requests race the still-initializing indexer/prover.
60+
for attempt in 0..120 {
61+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
62+
break;
63+
}
64+
assert!(attempt < 119, "indexer did not become healthy in time");
65+
tokio::time::sleep(Duration::from_secs(1)).await;
66+
}
5867

5968
rpc
6069
}

basic-operations/anchor/burn/programs/burn/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ async fn start_validator_and_connect() -> LightClient {
5252
tokio::time::sleep(Duration::from_secs(1)).await;
5353
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5454
}
55-
tokio::time::sleep(Duration::from_secs(10)).await;
55+
56+
// Wait for the indexer + prover to be ready (not just the validator RPC),
57+
// otherwise proof requests race the still-initializing indexer/prover.
58+
for attempt in 0..120 {
59+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
60+
break;
61+
}
62+
assert!(attempt < 119, "indexer did not become healthy in time");
63+
tokio::time::sleep(Duration::from_secs(1)).await;
64+
}
5665

5766
rpc
5867
}

basic-operations/anchor/close/programs/close/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ async fn start_validator_and_connect() -> LightClient {
5151
tokio::time::sleep(Duration::from_secs(1)).await;
5252
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5353
}
54-
tokio::time::sleep(Duration::from_secs(10)).await;
54+
55+
// Wait for the indexer + prover to be ready (not just the validator RPC),
56+
// otherwise proof requests race the still-initializing indexer/prover.
57+
for attempt in 0..120 {
58+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
59+
break;
60+
}
61+
assert!(attempt < 119, "indexer did not become healthy in time");
62+
tokio::time::sleep(Duration::from_secs(1)).await;
63+
}
5564

5665
rpc
5766
}

basic-operations/anchor/create/programs/create/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ async fn start_validator_and_connect() -> LightClient {
5555
tokio::time::sleep(Duration::from_secs(1)).await;
5656
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5757
}
58-
tokio::time::sleep(Duration::from_secs(10)).await;
58+
59+
// Wait for the indexer + prover to be ready (not just the validator RPC),
60+
// otherwise proof requests race the still-initializing indexer/prover.
61+
for attempt in 0..120 {
62+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
63+
break;
64+
}
65+
assert!(attempt < 119, "indexer did not become healthy in time");
66+
tokio::time::sleep(Duration::from_secs(1)).await;
67+
}
5968

6069
rpc
6170
}

basic-operations/anchor/reinit/programs/reinit/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ async fn start_validator_and_connect() -> LightClient {
5454
tokio::time::sleep(Duration::from_secs(1)).await;
5555
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5656
}
57-
tokio::time::sleep(Duration::from_secs(10)).await;
57+
58+
// Wait for the indexer + prover to be ready (not just the validator RPC),
59+
// otherwise proof requests race the still-initializing indexer/prover.
60+
for attempt in 0..120 {
61+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
62+
break;
63+
}
64+
assert!(attempt < 119, "indexer did not become healthy in time");
65+
tokio::time::sleep(Duration::from_secs(1)).await;
66+
}
5867

5968
rpc
6069
}

basic-operations/anchor/update/programs/update/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ async fn start_validator_and_connect() -> LightClient {
5555
tokio::time::sleep(Duration::from_secs(1)).await;
5656
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5757
}
58-
tokio::time::sleep(Duration::from_secs(10)).await;
58+
59+
// Wait for the indexer + prover to be ready (not just the validator RPC),
60+
// otherwise proof requests race the still-initializing indexer/prover.
61+
for attempt in 0..120 {
62+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
63+
break;
64+
}
65+
assert!(attempt < 119, "indexer did not become healthy in time");
66+
tokio::time::sleep(Duration::from_secs(1)).await;
67+
}
5968

6069
rpc
6170
}

basic-operations/native/programs/burn/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ async fn start_validator_and_connect() -> LightClient {
5151
tokio::time::sleep(Duration::from_secs(1)).await;
5252
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5353
}
54-
tokio::time::sleep(Duration::from_secs(10)).await;
54+
55+
// Wait for the indexer + prover to be ready (not just the validator RPC),
56+
// otherwise proof requests race the still-initializing indexer/prover.
57+
for attempt in 0..120 {
58+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
59+
break;
60+
}
61+
assert!(attempt < 119, "indexer did not become healthy in time");
62+
tokio::time::sleep(Duration::from_secs(1)).await;
63+
}
5564

5665
rpc
5766
}

basic-operations/native/programs/close/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ async fn start_validator_and_connect() -> LightClient {
5151
tokio::time::sleep(Duration::from_secs(1)).await;
5252
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5353
}
54-
tokio::time::sleep(Duration::from_secs(10)).await;
54+
55+
// Wait for the indexer + prover to be ready (not just the validator RPC),
56+
// otherwise proof requests race the still-initializing indexer/prover.
57+
for attempt in 0..120 {
58+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
59+
break;
60+
}
61+
assert!(attempt < 119, "indexer did not become healthy in time");
62+
tokio::time::sleep(Duration::from_secs(1)).await;
63+
}
5564

5665
rpc
5766
}

basic-operations/native/programs/create/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ async fn start_validator_and_connect() -> LightClient {
5050
tokio::time::sleep(Duration::from_secs(1)).await;
5151
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5252
}
53-
tokio::time::sleep(Duration::from_secs(10)).await;
53+
54+
// Wait for the indexer + prover to be ready (not just the validator RPC),
55+
// otherwise proof requests race the still-initializing indexer/prover.
56+
for attempt in 0..120 {
57+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
58+
break;
59+
}
60+
assert!(attempt < 119, "indexer did not become healthy in time");
61+
tokio::time::sleep(Duration::from_secs(1)).await;
62+
}
5463

5564
rpc
5665
}

basic-operations/native/programs/reinit/tests/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ async fn start_validator_and_connect() -> LightClient {
5252
tokio::time::sleep(Duration::from_secs(1)).await;
5353
rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
5454
}
55-
tokio::time::sleep(Duration::from_secs(10)).await;
55+
56+
// Wait for the indexer + prover to be ready (not just the validator RPC),
57+
// otherwise proof requests race the still-initializing indexer/prover.
58+
for attempt in 0..120 {
59+
if matches!(rpc.get_indexer_health(None).await, Ok(true)) {
60+
break;
61+
}
62+
assert!(attempt < 119, "indexer did not become healthy in time");
63+
tokio::time::sleep(Duration::from_secs(1)).await;
64+
}
5665

5766
rpc
5867
}

0 commit comments

Comments
 (0)