1
- use crate :: common:: fio_run_verify;
1
+ use crate :: common:: { dd_random_file , fio_run_verify} ;
2
2
use common:: compose:: {
3
3
rpc:: v0:: {
4
4
mayastor:: {
@@ -347,11 +347,80 @@ async fn persistent_store_connection() {
347
347
assert ! ( get_nexus( ms1, nexus_uuid) . await . is_some( ) ) ;
348
348
}
349
349
350
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
351
+ async fn self_shutdown_destroy ( ) {
352
+ let test = start_infrastructure_ ( "self_shutdown_destroy" , Some ( "1" ) ) . await ;
353
+ let grpc = GrpcConnect :: new ( & test) ;
354
+ let ms1 = & mut grpc. grpc_handle ( "ms1" ) . await . unwrap ( ) ;
355
+ let ms2 = & mut grpc. grpc_handle ( "ms2" ) . await . unwrap ( ) ;
356
+ let ms3 = & mut grpc. grpc_handle ( "ms3" ) . await . unwrap ( ) ;
357
+
358
+ // Create bdevs and share over nvmf.
359
+ let child1 = create_and_share_bdevs ( ms2, CHILD1_UUID ) . await ;
360
+ let child2 = create_and_share_bdevs ( ms3, CHILD2_UUID ) . await ;
361
+
362
+ // Create and publish a nexus.
363
+ let nexus_uuid = "8272e9d3-3738-4e33-b8c3-769d8eed5771" ;
364
+ create_nexus ( ms1, nexus_uuid, vec ! [ child1. clone( ) , child2. clone( ) ] ) . await ;
365
+ let nexus_uri = publish_nexus ( ms1, nexus_uuid) . await ;
366
+
367
+ // Create and connect NVMF target.
368
+ let target = libnvme_rs:: NvmeTarget :: try_from ( nexus_uri. clone ( ) )
369
+ . unwrap ( )
370
+ . with_reconnect_delay ( Some ( 1 ) )
371
+ . ctrl_loss_timeout ( Some ( 1 ) )
372
+ . with_rand_hostnqn ( true ) ;
373
+ target. connect ( ) . unwrap ( ) ;
374
+
375
+ // simulate node with child and etcd going down
376
+ test. stop ( "etcd" ) . await . unwrap ( ) ;
377
+ test. stop ( "ms3" ) . await . unwrap ( ) ;
378
+
379
+ // allow pstor to timeout and self shutdown
380
+ // todo: use wait loop
381
+ tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
382
+
383
+ let nexus = get_nexus ( ms1, nexus_uuid) . await . unwrap ( ) ;
384
+ assert_eq ! ( nexus. state, NexusState :: NexusShutdown as i32 ) ;
385
+
386
+ let devices = target. block_devices ( 2 ) . unwrap ( ) ;
387
+ let fio_hdl = tokio:: spawn ( async move {
388
+ dd_random_file ( & devices[ 0 ] . to_string ( ) , 4096 , 1 )
389
+ } ) ;
390
+
391
+ test. start ( "etcd" ) . await . unwrap ( ) ;
392
+
393
+ ms1. mayastor
394
+ . destroy_nexus ( DestroyNexusRequest {
395
+ uuid : nexus_uuid. to_string ( ) ,
396
+ } )
397
+ . await
398
+ . expect ( "Failed to destroy nexus" ) ;
399
+
400
+ // Disconnect NVMF target
401
+ target. disconnect ( ) . unwrap ( ) ;
402
+
403
+ fio_hdl. await . unwrap ( ) ;
404
+ }
405
+
350
406
/// Start the containers for the tests.
351
407
async fn start_infrastructure ( test_name : & str ) -> ComposeTest {
408
+ start_infrastructure_ ( test_name, None ) . await
409
+ }
410
+
411
+ /// Start the containers for the tests.
412
+ async fn start_infrastructure_ (
413
+ test_name : & str ,
414
+ ps_retries : Option < & str > ,
415
+ ) -> ComposeTest {
352
416
common:: composer_init ( ) ;
353
417
354
418
let etcd_endpoint = format ! ( "http://etcd.{test_name}:2379" ) ;
419
+ let mut args = vec ! [ "-p" , & etcd_endpoint] ;
420
+ if let Some ( retries) = ps_retries {
421
+ args. extend ( [ "--ps-retries" , retries] ) ;
422
+ }
423
+
355
424
Builder :: new ( )
356
425
. name ( test_name)
357
426
. add_container_spec (
@@ -371,20 +440,17 @@ async fn start_infrastructure(test_name: &str) -> ComposeTest {
371
440
)
372
441
. add_container_bin (
373
442
"ms1" ,
374
- Binary :: from_dbg ( "io-engine" ) . with_args ( vec ! [ "-p" , & etcd_endpoint ] ) ,
443
+ Binary :: from_dbg ( "io-engine" ) . with_args ( args . clone ( ) ) ,
375
444
)
376
445
. add_container_bin (
377
446
"ms2" ,
378
- Binary :: from_dbg ( "io-engine" ) . with_args ( vec ! [ "-p" , & etcd_endpoint ] ) ,
447
+ Binary :: from_dbg ( "io-engine" ) . with_args ( args . clone ( ) ) ,
379
448
)
380
449
. add_container_bin (
381
450
"ms3" ,
382
- Binary :: from_dbg ( "io-engine" ) . with_args ( vec ! [ "-p" , & etcd_endpoint] ) ,
383
- )
384
- . add_container_bin (
385
- "ms4" ,
386
- Binary :: from_dbg ( "io-engine" ) . with_args ( vec ! [ "-p" , & etcd_endpoint] ) ,
451
+ Binary :: from_dbg ( "io-engine" ) . with_args ( args. clone ( ) ) ,
387
452
)
453
+ . add_container_bin ( "ms4" , Binary :: from_dbg ( "io-engine" ) . with_args ( args) )
388
454
. build ( )
389
455
. await
390
456
. unwrap ( )
0 commit comments