Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit e97299c

Browse files
Test cases for jobs created
1 parent d0fac16 commit e97299c

File tree

4 files changed

+157
-27
lines changed

4 files changed

+157
-27
lines changed

Cargo.lock

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ name = "agent-integration-tests"
77
version = "0.1.0"
88

99
[dependencies]
10-
integration-test-commons = { git = "https://github.com/stackabletech/integration-test-commons.git", tag = "0.1.0" }
10+
integration-test-commons = { git = "https://github.com/stackabletech/integration-test-commons.git", branch = "verify_status" }
1111
futures = "0.3"
1212
tokio = { version = "1.7", features = ["macros", "rt-multi-thread"] }

tests/job.rs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
use integration_test_commons::test::prelude::*;
2+
3+
struct ExitService<'a> {
4+
client: &'a TestKubeClient,
5+
pod: TemporaryResource<'a, Pod>,
6+
}
7+
8+
impl<'a> ExitService<'a> {
9+
pub fn new(client: &'a TestKubeClient, exit_code: i32) -> Self {
10+
setup_repository(&client);
11+
12+
let pod = TemporaryResource::new(
13+
&client,
14+
&with_unique_name(&format!(
15+
"
16+
apiVersion: v1
17+
kind: Pod
18+
metadata:
19+
name: agent-service-integration-test-job
20+
spec:
21+
containers:
22+
- name: exit-service
23+
image: exit-service:1.0.0
24+
command:
25+
- exit-service-1.0.0/start.sh
26+
env:
27+
- name: EXIT_CODE
28+
value: {exit_code}
29+
restartPolicy: Never
30+
tolerations:
31+
- key: kubernetes.io/arch
32+
operator: Equal
33+
value: stackable-linux
34+
",
35+
exit_code = exit_code
36+
)),
37+
);
38+
39+
ExitService { client, pod }
40+
}
41+
42+
pub fn verify_terminated(&mut self) {
43+
self.client.verify_status::<Pod, _>(&self.pod, |pod| {
44+
let phase = ExitService::phase_from(pod);
45+
let container_terminated = ExitService::terminated_container_state_from(pod).is_some();
46+
(phase == "Succeeded" || phase == "Failed") && container_terminated
47+
});
48+
49+
self.pod.update();
50+
}
51+
52+
pub fn phase(&self) -> String {
53+
ExitService::phase_from(&self.pod)
54+
}
55+
56+
pub fn terminated_container_state(&self) -> Option<ContainerStateTerminated> {
57+
ExitService::terminated_container_state_from(&self.pod)
58+
}
59+
60+
fn phase_from(pod: &Pod) -> String {
61+
pod.status
62+
.as_ref()
63+
.and_then(|status| status.phase.clone())
64+
.unwrap_or_else(|| String::from("Unknown"))
65+
}
66+
67+
fn terminated_container_state_from(pod: &Pod) -> Option<ContainerStateTerminated> {
68+
pod.status
69+
.as_ref()
70+
.and_then(|status| status.container_statuses.as_ref())
71+
.and_then(|container_statuses| container_statuses.first().to_owned())
72+
.and_then(|container_status| container_status.state.as_ref())
73+
.and_then(|state| state.terminated.to_owned())
74+
}
75+
}
76+
77+
#[test]
78+
fn successful_job_should_have_phase_succeeded_and_error_code_0() {
79+
let client = TestKubeClient::new();
80+
81+
let exit_code = 0;
82+
let mut exit_service = ExitService::new(&client, exit_code);
83+
84+
exit_service.verify_terminated();
85+
86+
asserting("phase")
87+
.that(&exit_service.phase())
88+
.is_equal_to(String::from("Succeeded"));
89+
90+
let container_state = exit_service
91+
.terminated_container_state()
92+
.expect("Terminated container state expected");
93+
asserting("exit code")
94+
.that(&container_state.exit_code)
95+
.is_equal_to(0);
96+
asserting("message")
97+
.that(&container_state.message)
98+
.is_equal_to(Some(String::from("Completed")));
99+
asserting("reason")
100+
.that(&container_state.message)
101+
.is_equal_to(Some(String::from("Completed")));
102+
}
103+
104+
#[test]
105+
fn failed_job_should_have_phase_failed_and_error_code_1() {
106+
let client = TestKubeClient::new();
107+
108+
// All non-zero exit codes are mapped by the agent to 1.
109+
let exit_code = 42;
110+
let mut exit_service = ExitService::new(&client, exit_code);
111+
112+
exit_service.verify_terminated();
113+
114+
asserting("phase")
115+
.that(&exit_service.phase())
116+
.is_equal_to(String::from("Failed"));
117+
118+
let container_state = exit_service
119+
.terminated_container_state()
120+
.expect("Terminated container state expected");
121+
asserting("exit code")
122+
.that(&container_state.exit_code)
123+
.is_equal_to(1);
124+
asserting("message")
125+
.that(&container_state.message)
126+
.is_equal_to(Some(String::from("Error")));
127+
asserting("reason")
128+
.that(&container_state.message)
129+
.is_equal_to(Some(String::from("Error")));
130+
}

tests/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async fn starting_and_stopping_100_pods_simultaneously_should_succeed() {
7474
.expect("Kubernetes client could not be created");
7575
client.timeouts.create = Duration::from_secs(60);
7676
client.timeouts.delete = Duration::from_secs(60);
77-
client.timeouts.verify_pod_condition = Duration::from_secs(60);
77+
client.timeouts.verify_status = Duration::from_secs(60);
7878

7979
setup_repository_async(&client)
8080
.await

0 commit comments

Comments
 (0)