github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/events.bats (about) 1 #!/usr/bin/env bats 2 3 load helpers 4 5 function setup() { 6 teardown_busybox 7 setup_busybox 8 } 9 10 function teardown() { 11 teardown_busybox 12 } 13 14 @test "events --stats" { 15 # run busybox detached 16 runc run -d --console /dev/pts/ptmx test_busybox 17 [ "$status" -eq 0 ] 18 19 # check state 20 wait_for_container 15 1 test_busybox 21 22 # generate stats 23 runc events --stats test_busybox 24 [ "$status" -eq 0 ] 25 [[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]] 26 [[ "${lines[0]}" == *"data"* ]] 27 } 28 29 @test "events --interval default " { 30 # run busybox detached 31 runc run -d --console /dev/pts/ptmx test_busybox 32 [ "$status" -eq 0 ] 33 34 # check state 35 wait_for_container 15 1 test_busybox 36 37 # spawn two sub processes (shells) 38 # the first sub process is an event logger that sends stats events to events.log 39 # the second sub process waits for an event that incudes test_busybox then 40 # kills the test_busybox container which causes the event logger to exit 41 (__runc events test_busybox > events.log) & 42 ( 43 retry 10 1 eval "grep -q 'test_busybox' events.log" 44 teardown_running_container test_busybox 45 ) & 46 wait # wait for the above sub shells to finish 47 48 [ -e events.log ] 49 50 run cat events.log 51 [ "$status" -eq 0 ] 52 [[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]] 53 [[ "${lines[0]}" == *"data"* ]] 54 } 55 56 @test "events --interval 1s " { 57 # run busybox detached 58 runc run -d --console /dev/pts/ptmx test_busybox 59 [ "$status" -eq 0 ] 60 61 # check state 62 wait_for_container 15 1 test_busybox 63 64 # spawn two sub processes (shells) 65 # the first sub process is an event logger that sends stats events to events.log once a second 66 # the second sub process tries 3 times for an event that incudes test_busybox 67 # pausing 1s between each attempt then kills the test_busybox container which 68 # causes the event logger to exit 69 (__runc events --interval 1s test_busybox > events.log) & 70 ( 71 retry 3 1 eval "grep -q 'test_busybox' events.log" 72 teardown_running_container test_busybox 73 ) & 74 wait # wait for the above sub shells to finish 75 76 [ -e events.log ] 77 78 run eval "grep -q 'test_busybox' events.log" 79 [ "$status" -eq 0 ] 80 } 81 82 @test "events --interval 100ms " { 83 # run busybox detached 84 runc run -d --console /dev/pts/ptmx test_busybox 85 [ "$status" -eq 0 ] 86 87 # check state 88 wait_for_container 15 1 test_busybox 89 90 #prove there is no carry over of events.log from a prior test 91 [ ! -e events.log ] 92 93 # spawn two sub processes (shells) 94 # the first sub process is an event logger that sends stats events to events.log once every 100ms 95 # the second sub process tries 3 times for an event that incudes test_busybox 96 # pausing 100s between each attempt then kills the test_busybox container which 97 # causes the event logger to exit 98 (__runc events --interval 100ms test_busybox > events.log) & 99 ( 100 retry 3 0.100 eval "grep -q 'test_busybox' events.log" 101 teardown_running_container test_busybox 102 ) & 103 wait # wait for the above sub shells to finish 104 105 [ -e events.log ] 106 107 run eval "grep -q 'test_busybox' events.log" 108 [ "$status" -eq 0 ] 109 }