Skip to content

Commit 603ae23

Browse files
committed
exercise root and nested start stop free paths
1 parent 33b061a commit 603ae23

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

auraed/src/cells/cell_service/cell_service.rs

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ mod tests {
569569
logging::log_channel::LogChannel,
570570
};
571571
use iter_tools::Itertools;
572+
use proto::cells::Executable;
572573
use std::ffi::OsString;
573574
use test_helpers::*;
574575

@@ -659,21 +660,47 @@ mod tests {
659660
(None, None, None),
660661
));
661662

663+
let command = "tail -f /dev/null";
664+
665+
// Cover the default root cell start/stop entry points.
666+
let root_executable_name =
667+
format!("ae-exec-root-{}", uuid::Uuid::new_v4());
668+
let result = service
669+
.start(validated_start_request(&root_executable_name, command))
670+
.await;
671+
assert!(result.is_ok());
672+
673+
let response = result.unwrap().into_inner();
674+
assert!(response.pid != 0);
675+
676+
assert!(service
677+
.stop(validated_stop_request(&root_executable_name))
678+
.await
679+
.is_ok());
680+
662681
let cell_name = format!("ae-test-{}", uuid::Uuid::new_v4());
663682
assert!(service.allocate(allocate_request(&cell_name)).await.is_ok());
683+
let cell_name_ref = CellName::from(cell_name.as_str());
664684

665685
let executable_name = format!("ae-exec-{}", uuid::Uuid::new_v4());
666-
let command = "tail -f /dev/null";
667-
let result =
668-
service.start(start_request(&executable_name, command)).await;
686+
// start/stop/free need to run within the allocated cell
687+
let result = service
688+
.start_in_cell(&cell_name_ref, start_request(&executable_name, command))
689+
.await;
669690
assert!(result.is_ok());
670691

671692
let response = result.unwrap().into_inner();
672693
assert!(response.pid != 0);
673694

674-
assert!(service.stop(stop_request(&executable_name)).await.is_ok());
695+
assert!(service
696+
.stop_in_cell(&cell_name_ref, stop_request(&executable_name))
697+
.await
698+
.is_ok());
675699

676-
assert!(service.free(free_request(&cell_name)).await.is_ok());
700+
assert!(service
701+
.free(free_request(&cell_name))
702+
.await
703+
.is_ok());
677704
}
678705

679706
/// Helper function to create a ValidatedCellServiceAllocateRequest.
@@ -708,7 +735,7 @@ mod tests {
708735
ValidatedCellServiceAllocateRequest { cell }
709736
}
710737

711-
fn start_request(
738+
fn validated_start_request(
712739
executable_name: &str,
713740
command: &str,
714741
) -> ValidatedCellServiceStartRequest {
@@ -726,13 +753,40 @@ mod tests {
726753
}
727754
}
728755

729-
fn stop_request(executable_name: &str) -> ValidatedCellServiceStopRequest {
756+
fn validated_stop_request(
757+
executable_name: &str,
758+
) -> ValidatedCellServiceStopRequest {
730759
ValidatedCellServiceStopRequest {
731760
cell_name: None,
732761
executable_name: ExecutableName::new(String::from(executable_name)),
733762
}
734763
}
735764

765+
fn start_request(
766+
executable_name: &str,
767+
command: &str,
768+
) -> CellServiceStartRequest {
769+
let executable = Executable {
770+
name: executable_name.to_string(),
771+
command: command.to_string(),
772+
description: String::new(),
773+
};
774+
775+
CellServiceStartRequest {
776+
cell_name: None,
777+
executable: Some(executable),
778+
uid: None,
779+
gid: None,
780+
}
781+
}
782+
783+
fn stop_request(executable_name: &str) -> CellServiceStopRequest {
784+
CellServiceStopRequest {
785+
cell_name: None,
786+
executable_name: executable_name.to_string(),
787+
}
788+
}
789+
736790
fn free_request(cell_name: &str) -> ValidatedCellServiceFreeRequest {
737791
// Return the validated free request
738792
ValidatedCellServiceFreeRequest { cell_name: CellName::from(cell_name) }

0 commit comments

Comments
 (0)