use nucleus::isolation::NamespaceState;
use nucleus::StateTransition;
#[test]
fn test_namespace_state_machine_valid_path() {
let states = [
NamespaceState::Uninitialized,
NamespaceState::Unshared,
NamespaceState::Entered,
NamespaceState::Cleaned,
];
for i in 0..states.len() - 1 {
assert!(
states[i].can_transition_to(&states[i + 1]),
"Invalid transition from {:?} to {:?}",
states[i],
states[i + 1]
);
}
}
#[test]
fn test_namespace_property_isolation_integrity() {
let state = NamespaceState::Entered;
assert!(state.can_transition_to(&NamespaceState::Entered));
assert!(state.can_transition_to(&NamespaceState::Cleaned));
assert!(!state.can_transition_to(&NamespaceState::Uninitialized));
assert!(!state.can_transition_to(&NamespaceState::Unshared));
}
#[test]
fn test_namespace_property_terminal_stable() {
let state = NamespaceState::Cleaned;
assert!(state.is_terminal());
assert!(!state.can_transition_to(&NamespaceState::Uninitialized));
assert!(!state.can_transition_to(&NamespaceState::Unshared));
assert!(!state.can_transition_to(&NamespaceState::Entered));
assert!(state.can_transition_to(&NamespaceState::Cleaned));
}
#[test]
fn test_namespace_property_liveness() {
let states = [
NamespaceState::Uninitialized,
NamespaceState::Unshared,
NamespaceState::Entered,
];
for initial in states {
assert!(
!initial.is_terminal(),
"{:?} should not be terminal",
initial
);
let mut current = initial;
for _ in 0..10 {
if current.is_terminal() {
break;
}
current = match current {
NamespaceState::Uninitialized => NamespaceState::Unshared,
NamespaceState::Unshared => NamespaceState::Entered,
NamespaceState::Entered => NamespaceState::Cleaned,
NamespaceState::Cleaned => break,
};
}
assert!(
current.is_terminal(),
"Should reach terminal from {:?}",
initial
);
}
}
#[test]
fn test_namespace_no_state_skipping() {
assert!(!NamespaceState::Uninitialized.can_transition_to(&NamespaceState::Entered));
assert!(!NamespaceState::Uninitialized.can_transition_to(&NamespaceState::Cleaned));
assert!(!NamespaceState::Unshared.can_transition_to(&NamespaceState::Cleaned));
}
#[test]
fn test_namespace_no_backwards_transitions() {
assert!(!NamespaceState::Unshared.can_transition_to(&NamespaceState::Uninitialized));
assert!(!NamespaceState::Entered.can_transition_to(&NamespaceState::Unshared));
assert!(!NamespaceState::Cleaned.can_transition_to(&NamespaceState::Entered));
}