-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathserver_state_machine.rs
91 lines (74 loc) · 3.08 KB
/
server_state_machine.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Tests verifying the server state machine.
use std::time::Duration;
use phd_testcase::*;
use propolis_client::types::InstanceState;
#[phd_testcase]
async fn instance_start_stop_test(ctx: &Framework) {
let mut vm = ctx.spawn_default_vm("instance_ensure_running_test").await?;
vm.instance_ensure().await?;
let instance = vm.get().await?.instance;
assert_eq!(instance.state, InstanceState::Creating);
vm.launch().await?;
vm.wait_for_state(InstanceState::Running, Duration::from_secs(60)).await?;
vm.stop().await?;
vm.wait_for_state(InstanceState::Destroyed, Duration::from_secs(60))
.await?;
}
#[phd_testcase]
async fn instance_stop_causes_destroy_test(ctx: &Framework) {
let mut vm =
ctx.spawn_default_vm("instance_stop_causes_destroy_test").await?;
vm.launch().await?;
vm.stop().await?;
vm.wait_for_state(InstanceState::Destroyed, Duration::from_secs(60))
.await?;
assert!(matches!(
vm.run().await.unwrap_err().status().unwrap(),
http::status::StatusCode::FAILED_DEPENDENCY
));
assert!(matches!(
vm.stop().await.unwrap_err().status().unwrap(),
http::status::StatusCode::FAILED_DEPENDENCY
));
assert!(matches!(
vm.reset().await.unwrap_err().status().unwrap(),
http::status::StatusCode::FAILED_DEPENDENCY
));
}
#[phd_testcase]
async fn instance_reset_test(ctx: &Framework) {
let mut vm =
ctx.spawn_default_vm("instance_reset_returns_to_running_test").await?;
assert!(vm.reset().await.is_err());
vm.launch().await?;
vm.wait_for_state(InstanceState::Running, Duration::from_secs(60)).await?;
// Because "Rebooting" is not a steady state, the Propolis state worker may
// transition the instance from Running to Rebooting to Running before the
// test gets a chance to monitor its state any further. Thus, it's not safe
// to test that the Rebooting state was observed here.
vm.reset().await?;
vm.wait_for_state(InstanceState::Running, Duration::from_secs(60)).await?;
// Queue multiple reset attempts. These should all succeed, even though
// Propolis will only allow one reboot to be enqueued at a time. Once again,
// the specific number of reboots that will be queued depends on factors
// outside of the test's control.
for _ in 0..10 {
vm.reset().await?;
}
vm.wait_for_state(InstanceState::Running, Duration::from_secs(60)).await?;
vm.stop().await?;
vm.wait_for_state(InstanceState::Destroyed, Duration::from_secs(60))
.await?;
assert!(vm.reset().await.is_err());
}
#[phd_testcase]
async fn instance_reset_requires_running_test(ctx: &Framework) {
let mut vm =
ctx.spawn_default_vm("instance_reset_requires_running_test").await?;
assert!(vm.reset().await.is_err());
vm.launch().await?;
vm.wait_for_state(InstanceState::Running, Duration::from_secs(60)).await?;
}