Skip to content

Commit 59fbb90

Browse files
authored
fix: stuck integration test (#258)
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
1 parent cefe27a commit 59fbb90

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

ci/run-bridge.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TRUSTED_PEERS_FILE="$SHARED_DIR/trusted_peers"
2626
wait_for_provision() {
2727
echo "Waiting for the validator node to start"
2828
while [[ ! ( -e "$GENESIS_HASH_FILE" && -e "$NODE_KEY_FILE" ) ]]; do
29-
sleep 0.1
29+
sleep 1
3030
done
3131

3232
echo "Validator is ready"

crates/tests/src/lib.rs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use prism_storage::{
1919
use rand::{rngs::StdRng, Rng, SeedableRng};
2020
use sp1_sdk::{HashableKey, Prover as _, ProverClient};
2121
use std::sync::Arc;
22-
use tokio::{spawn, time::Duration};
22+
use tokio::{spawn, sync::mpsc, time::Duration};
2323

2424
use tempfile::TempDir;
2525

@@ -76,6 +76,7 @@ async fn test_light_client_prover_talking() -> Result<()> {
7676
)?);
7777

7878
let event_channel = EventChannel::new();
79+
let (shutdown_tx, mut shutdown_rx) = mpsc::channel::<()>(1);
7980

8081
let lightclient = Arc::new(LightClient::new(
8182
lc_da_layer.clone(),
@@ -86,18 +87,18 @@ async fn test_light_client_prover_talking() -> Result<()> {
8687
));
8788

8889
let prover_clone = prover.clone();
89-
spawn(async move {
90+
let _prover_handle = spawn(async move {
9091
debug!("starting prover");
9192
prover_clone.run().await.unwrap();
9293
});
9394

9495
let lc_clone = lightclient.clone();
95-
spawn(async move {
96+
let _lc_handle = spawn(async move {
9697
debug!("starting light client");
9798
lc_clone.run().await.unwrap();
9899
});
99100

100-
spawn(async move {
101+
let tx_handle = spawn(async move {
101102
let mut transaction_builder = TestTransactionBuilder::new();
102103
let register_service_req = transaction_builder
103104
.register_service_with_random_keys(service_algorithm, "test_service")
@@ -109,6 +110,12 @@ async fn test_light_client_prover_talking() -> Result<()> {
109110
let mut added_account_ids: Vec<String> = Vec::new();
110111

111112
loop {
113+
// Check if we should shut down
114+
if shutdown_rx.try_recv().is_ok() {
115+
debug!("Transaction generator received shutdown signal");
116+
break;
117+
}
118+
112119
// Create 1 to 3 new accounts
113120
let num_new_accounts = rng.gen_range(1..=3);
114121
for _ in 0..num_new_accounts {
@@ -173,14 +180,32 @@ async fn test_light_client_prover_talking() -> Result<()> {
173180
}
174181
});
175182

176-
let mut rx = lc_da_layer.clone().subscribe_to_heights();
177-
let initial_height = rx.recv().await.unwrap();
178-
while let Ok(height) = rx.recv().await {
179-
debug!("received height {}", height);
180-
if height >= initial_height + 50 {
181-
break;
183+
// Monitor height and stop test when target height is reached
184+
let height_monitor = spawn(async move {
185+
let mut rx = bridge_da_layer.clone().subscribe_to_heights();
186+
let initial_height = rx.recv().await.unwrap();
187+
debug!("Initial height: {}", initial_height);
188+
let target_height = initial_height + 50;
189+
190+
while let Ok(height) = rx.recv().await {
191+
debug!("Received height {}", height);
192+
193+
if height >= target_height {
194+
info!("Reached target height {}. Stopping test.", target_height);
195+
let _ = shutdown_tx.send(()).await;
196+
break;
197+
}
182198
}
183-
}
199+
});
200+
201+
// Wait for height monitor to complete
202+
height_monitor.await?;
203+
204+
// Wait for transaction generator to complete
205+
tx_handle.await?;
206+
207+
// We could add code to gracefully shut down the prover and light client here
208+
// but for test purposes, we'll just return
184209

185210
Ok(())
186211
}

0 commit comments

Comments
 (0)