Skip to content

Commit bb23f70

Browse files
Fix durability test flake (#5233)
# Description of Changes Removes a race(sleep) in `local_durability_crashes_on_new_segment_if_not_enough_space()` where we might not wait long enough for `fallocate` to fail and crash the durability actor. # API and ABI breaking changes N/A # Expected complexity level and risk 1 # Testing The test should no longer flake.
1 parent d5c75d9 commit bb23f70

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

crates/durability/tests/io/fallocate.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use spacetimedb_commitlog::{
3838
use spacetimedb_durability::{local::OpenError, Durability, Transaction, Txdata};
3939
use spacetimedb_paths::{server::ReplicaDir, FromPathUnchecked};
4040
use tempfile::{NamedTempFile, TempDir};
41-
use tokio::{sync::watch, time::sleep};
41+
use tokio::{sync::watch, time::timeout};
4242

4343
const MB: u64 = 1024 * 1024;
4444

@@ -92,6 +92,7 @@ async fn local_durability_crashes_on_new_segment_if_not_enough_space() {
9292
new_segment_tx.send_replace(());
9393
});
9494
let durability = local_durability(replica_dir, 256 * MB, Some(on_new_segment)).await?;
95+
let mut durable_offset = durability.durable_tx_offset();
9596
let txdata = txdata();
9697

9798
// Mark initial segment as seen.
@@ -102,8 +103,13 @@ async fn local_durability_crashes_on_new_segment_if_not_enough_space() {
102103
}
103104
// Ensure new segment is created.
104105
new_segment_rx.changed().await?;
105-
// Yield to give fallocate a chance to run (and fail).
106-
sleep(Duration::from_millis(5)).await;
106+
// Wait for fallocate to run (and fail).
107+
match timeout(Duration::from_secs(10), durable_offset.wait_for(256)).await {
108+
Ok(Err(_)) => {}
109+
Ok(Ok(offset)) => return Err(anyhow!("durability unexpectedly reached offset {offset}")),
110+
Err(_) => return Err(anyhow!("timed out waiting for durability actor to exit")),
111+
}
112+
107113
// Durability actor should have crashed, so this should panic.
108114
info!("trying append on crashed durability");
109115
durability.append_tx(Box::new(Transaction::from((256, txdata.clone()))));

0 commit comments

Comments
 (0)