github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/test/system/080-pause.bats (about) 1 #!/usr/bin/env bats -*- bats -*- 2 # 3 # tests for podman pause/unpause functionality 4 # 5 6 load helpers 7 8 @test "podman pause/unpause" { 9 if is_rootless && ! is_cgroupsv2; then 10 skip "'podman pause' (rootless) only works with cgroups v2" 11 fi 12 13 cname=$(random_string 10) 14 run_podman run -d --name $cname $IMAGE \ 15 sh -c 'while :;do date +%s;sleep 1;done' 16 cid="$output" 17 # Wait for first time value 18 wait_for_output '[0-9]\{10,\}' $cid 19 20 # Pause container, sleep a bit, unpause, sleep again to give process 21 # time to write a new post-restart time value. Pause by CID, unpause 22 # by name, just to exercise code paths. While paused, check 'ps' 23 # and 'inspect', then check again after restarting. 24 run_podman pause $cid 25 run_podman inspect --format '{{.State.Status}}' $cid 26 is "$output" "paused" "podman inspect .State.Status" 27 sleep 3 28 run_podman ps -a --format '{{.ID}} {{.Names}} {{.Status}}' 29 is "$output" "${cid:0:12} $cname paused" "podman ps on paused container" 30 run_podman unpause $cname 31 run_podman ps -a --format '{{.ID}} {{.Names}} {{.Status}}' 32 is "$output" "${cid:0:12} $cname Up .*" "podman ps on resumed container" 33 sleep 1 34 35 # Get full logs, and iterate through them computing delta_t between entries 36 run_podman logs $cid 37 i=1 38 max_delta=0 39 while [ $i -lt ${#lines[*]} ]; do 40 this_delta=$(( ${lines[$i]} - ${lines[$(($i - 1))]} )) 41 if [ $this_delta -gt $max_delta ]; then 42 max_delta=$this_delta 43 fi 44 i=$(( $i + 1 )) 45 done 46 47 # There should be a 3-4 second gap, *maybe* 5. Never 1 or 2, that 48 # would imply that the container never paused. 49 is "$max_delta" "[3456]" "delta t between paused and restarted" 50 51 run_podman rm -f $cname 52 53 # Pause/unpause on nonexistent name or id - these should all fail 54 run_podman 125 pause $cid 55 run_podman 125 pause $cname 56 run_podman 125 unpause $cid 57 run_podman 125 unpause $cname 58 } 59 60 # vim: filetype=sh