@@ -12,6 +12,8 @@ use crate::guest::Guest;
12
12
use crate :: up_main;
13
13
use crate :: BlockIO ;
14
14
use crate :: Buffer ;
15
+ use crate :: ClientFaultReason ;
16
+ use crate :: ClientStopReason ;
15
17
use crate :: ConnectionMode ;
16
18
use crate :: CrucibleError ;
17
19
use crate :: DsState ;
@@ -2998,6 +3000,19 @@ async fn test_bytes_based_barrier() {
2998
3000
harness. ds3 . ack_flush ( ) . await ;
2999
3001
}
3000
3002
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
+
3001
3016
/// Test for early rejection of writes if > 1 Downstairs is unavailable
3002
3017
#[ tokio:: test]
3003
3018
async fn fast_write_rejection ( ) {
@@ -3015,7 +3030,7 @@ async fn fast_write_rejection() {
3015
3030
harness. ds3 . ack_write ( ) . await ;
3016
3031
tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
3017
3032
let ds = harness. guest . downstairs_state ( ) . await . unwrap ( ) ;
3018
- assert_eq ! ( ds[ ClientId :: new( 0 ) ] , DsState :: Faulted ) ;
3033
+ assert_faulted ( & ds[ ClientId :: new ( 0 ) ] ) ;
3019
3034
assert_eq ! ( ds[ ClientId :: new( 1 ) ] , DsState :: Active ) ;
3020
3035
assert_eq ! ( ds[ ClientId :: new( 2 ) ] , DsState :: Active ) ;
3021
3036
@@ -3029,8 +3044,8 @@ async fn fast_write_rejection() {
3029
3044
harness. ds3 . ack_write ( ) . await ;
3030
3045
tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
3031
3046
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 ) ] ) ;
3034
3049
assert_eq ! ( ds[ ClientId :: new( 2 ) ] , DsState :: Active ) ;
3035
3050
3036
3051
// Subsequent writes should be rejected immediately
@@ -3058,7 +3073,7 @@ async fn read_with_one_fault() {
3058
3073
harness. ds3 . ack_write ( ) . await ;
3059
3074
tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
3060
3075
let ds = harness. guest . downstairs_state ( ) . await . unwrap ( ) ;
3061
- assert_eq ! ( ds[ ClientId :: new( 0 ) ] , DsState :: Faulted ) ;
3076
+ assert_faulted ( & ds[ ClientId :: new ( 0 ) ] ) ;
3062
3077
assert_eq ! ( ds[ ClientId :: new( 1 ) ] , DsState :: Active ) ;
3063
3078
assert_eq ! ( ds[ ClientId :: new( 2 ) ] , DsState :: Active ) ;
3064
3079
@@ -3081,8 +3096,8 @@ async fn read_with_one_fault() {
3081
3096
harness. ds3 . ack_write ( ) . await ;
3082
3097
tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
3083
3098
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 ) ] ) ;
3086
3101
assert_eq ! ( ds[ ClientId :: new( 2 ) ] , DsState :: Active ) ;
3087
3102
3088
3103
// Reads still work with 1x Downstairs
@@ -3111,9 +3126,9 @@ async fn fast_read_rejection() {
3111
3126
harness. ds3 . err_write ( ) . await ;
3112
3127
tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
3113
3128
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 ) ] ) ;
3117
3132
3118
3133
// Reads should return errors immediately
3119
3134
let mut buffer = Buffer :: new ( 1 , 512 ) ;
@@ -3139,7 +3154,7 @@ async fn fast_flush_rejection() {
3139
3154
h. await . unwrap ( ) ;
3140
3155
tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
3141
3156
let ds = harness. guest . downstairs_state ( ) . await . unwrap ( ) ;
3142
- assert_eq ! ( ds[ ClientId :: new( 0 ) ] , DsState :: Faulted ) ;
3157
+ assert_faulted ( & ds[ ClientId :: new ( 0 ) ] ) ;
3143
3158
assert_eq ! ( ds[ ClientId :: new( 1 ) ] , DsState :: Active ) ;
3144
3159
assert_eq ! ( ds[ ClientId :: new( 2 ) ] , DsState :: Active ) ;
3145
3160
@@ -3173,9 +3188,9 @@ async fn fast_flush_rejection() {
3173
3188
assert ! ( r. is_err( ) ) ;
3174
3189
tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
3175
3190
let ds = harness. guest . downstairs_state ( ) . await . unwrap ( ) ;
3176
- assert_eq ! ( ds[ ClientId :: new( 0 ) ] , DsState :: Faulted ) ;
3191
+ assert_faulted ( & ds[ ClientId :: new ( 0 ) ] ) ;
3177
3192
assert_eq ! ( ds[ ClientId :: new( 1 ) ] , DsState :: Active ) ;
3178
- assert_eq ! ( ds[ ClientId :: new( 2 ) ] , DsState :: Faulted ) ;
3193
+ assert_faulted ( & ds[ ClientId :: new ( 2 ) ] ) ;
3179
3194
3180
3195
// Subsequent flushes should fail immediately
3181
3196
match harness. guest . flush ( None ) . await {
0 commit comments