Skip to content

Commit dd1cf13

Browse files
committed
Fix unit tests
1 parent a12b3eb commit dd1cf13

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

upstairs/src/client.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,6 @@ impl DownstairsClient {
18961896
)
18971897
}
18981898

1899-
#[cfg(feature = "notify-nexus")]
19001899
pub(crate) fn id(&self) -> Option<Uuid> {
19011900
self.region_uuid
19021901
}

upstairs/src/dummy_downstairs_tests.rs

+27-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use crate::guest::Guest;
1212
use crate::up_main;
1313
use crate::BlockIO;
1414
use crate::Buffer;
15+
use crate::ClientFaultReason;
16+
use crate::ClientStopReason;
1517
use crate::ConnectionMode;
1618
use crate::CrucibleError;
1719
use crate::DsState;
@@ -2998,6 +3000,19 @@ async fn test_bytes_based_barrier() {
29983000
harness.ds3.ack_flush().await;
29993001
}
30003002

3003+
fn assert_faulted(s: &DsState) {
3004+
match s {
3005+
DsState::Stopping(ClientStopReason::Fault(
3006+
ClientFaultReason::RequestedFault,
3007+
))
3008+
| DsState::Connecting {
3009+
mode: ConnectionMode::Faulted,
3010+
..
3011+
} => (),
3012+
_ => panic!("invalid state: expected faulted, got {s:?}"),
3013+
}
3014+
}
3015+
30013016
/// Test for early rejection of writes if > 1 Downstairs is unavailable
30023017
#[tokio::test]
30033018
async fn fast_write_rejection() {
@@ -3015,7 +3030,7 @@ async fn fast_write_rejection() {
30153030
harness.ds3.ack_write().await;
30163031
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
30173032
let ds = harness.guest.downstairs_state().await.unwrap();
3018-
assert_eq!(ds[ClientId::new(0)], DsState::Faulted);
3033+
assert_faulted(&ds[ClientId::new(0)]);
30193034
assert_eq!(ds[ClientId::new(1)], DsState::Active);
30203035
assert_eq!(ds[ClientId::new(2)], DsState::Active);
30213036

@@ -3029,8 +3044,8 @@ async fn fast_write_rejection() {
30293044
harness.ds3.ack_write().await;
30303045
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
30313046
let ds = harness.guest.downstairs_state().await.unwrap();
3032-
assert_eq!(ds[ClientId::new(0)], DsState::Faulted);
3033-
assert_eq!(ds[ClientId::new(1)], DsState::Faulted);
3047+
assert_faulted(&ds[ClientId::new(0)]);
3048+
assert_faulted(&ds[ClientId::new(1)]);
30343049
assert_eq!(ds[ClientId::new(2)], DsState::Active);
30353050

30363051
// Subsequent writes should be rejected immediately
@@ -3058,7 +3073,7 @@ async fn read_with_one_fault() {
30583073
harness.ds3.ack_write().await;
30593074
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
30603075
let ds = harness.guest.downstairs_state().await.unwrap();
3061-
assert_eq!(ds[ClientId::new(0)], DsState::Faulted);
3076+
assert_faulted(&ds[ClientId::new(0)]);
30623077
assert_eq!(ds[ClientId::new(1)], DsState::Active);
30633078
assert_eq!(ds[ClientId::new(2)], DsState::Active);
30643079

@@ -3081,8 +3096,8 @@ async fn read_with_one_fault() {
30813096
harness.ds3.ack_write().await;
30823097
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
30833098
let ds = harness.guest.downstairs_state().await.unwrap();
3084-
assert_eq!(ds[ClientId::new(0)], DsState::Faulted);
3085-
assert_eq!(ds[ClientId::new(1)], DsState::Faulted);
3099+
assert_faulted(&ds[ClientId::new(0)]);
3100+
assert_faulted(&ds[ClientId::new(1)]);
30863101
assert_eq!(ds[ClientId::new(2)], DsState::Active);
30873102

30883103
// Reads still work with 1x Downstairs
@@ -3111,9 +3126,9 @@ async fn fast_read_rejection() {
31113126
harness.ds3.err_write().await;
31123127
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
31133128
let ds = harness.guest.downstairs_state().await.unwrap();
3114-
assert_eq!(ds[ClientId::new(0)], DsState::Faulted);
3115-
assert_eq!(ds[ClientId::new(1)], DsState::Faulted);
3116-
assert_eq!(ds[ClientId::new(2)], DsState::Faulted);
3129+
assert_faulted(&ds[ClientId::new(0)]);
3130+
assert_faulted(&ds[ClientId::new(1)]);
3131+
assert_faulted(&ds[ClientId::new(2)]);
31173132

31183133
// Reads should return errors immediately
31193134
let mut buffer = Buffer::new(1, 512);
@@ -3139,7 +3154,7 @@ async fn fast_flush_rejection() {
31393154
h.await.unwrap();
31403155
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
31413156
let ds = harness.guest.downstairs_state().await.unwrap();
3142-
assert_eq!(ds[ClientId::new(0)], DsState::Faulted);
3157+
assert_faulted(&ds[ClientId::new(0)]);
31433158
assert_eq!(ds[ClientId::new(1)], DsState::Active);
31443159
assert_eq!(ds[ClientId::new(2)], DsState::Active);
31453160

@@ -3173,9 +3188,9 @@ async fn fast_flush_rejection() {
31733188
assert!(r.is_err());
31743189
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
31753190
let ds = harness.guest.downstairs_state().await.unwrap();
3176-
assert_eq!(ds[ClientId::new(0)], DsState::Faulted);
3191+
assert_faulted(&ds[ClientId::new(0)]);
31773192
assert_eq!(ds[ClientId::new(1)], DsState::Active);
3178-
assert_eq!(ds[ClientId::new(2)], DsState::Faulted);
3193+
assert_faulted(&ds[ClientId::new(2)]);
31793194

31803195
// Subsequent flushes should fail immediately
31813196
match harness.guest.flush(None).await {

0 commit comments

Comments
 (0)