-
Notifications
You must be signed in to change notification settings - Fork 1
/
no_test_wait.bats
55 lines (41 loc) · 1.21 KB
/
no_test_wait.bats
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
#!/usr/bin/env bats
load helpers
function teardown(){
swarm_manage_cleanup
stop_docker
}
@test "docker run container" {
start_docker 3
swarm_manage
# run after 10 seconds, test_container will exit
run docker_swarm run -d --name test_container busybox sleep 3
[ "$status" -eq 0 ]
# make sure container exists and is up
run docker_swarm ps -l
[ "${#lines[@]}" -eq 2 ]
[[ "${lines[1]}" == *"test_container"* ]]
[[ "${lines[1]}" == *"Up"* ]]
# wait until exist
run docker_swarm wait test_container &
WAIT_PID=$!
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ]
[[ "${lines[0]}" == "0" ]]
sleep 3
kill -9 $WAIT_PID
}
# Spawn a child process:
(dosmth) & pid=$!
# in the background, sleep for 10 secs then kill that process
(sleep 10 && kill -9 $pid) &
or to get the exit codes as well:
# Spawn a child process:
(dosmth) & pid=$!
# in the background, sleep for 10 secs then kill that process
(sleep 10 && kill -9 $pid) & waiter=$!
# wait on our worker process and return the exitcode
exitcode=$(wait $pid && echo $?)
# kill the waiter subshell, if it still runs
kill -9 $waiter 2>/dev/null
# 0 if we killed the waiter, cause that means the process finished before the waiter
finished_gracefully=$?