ctdb-common: Switch to ETIMEDOUT from ETIME
[samba.git] / ctdb / tests / cunit / run_event_001.sh
1 #!/bin/sh
2
3 . "${TEST_SCRIPTS_DIR}/unit.sh"
4
5 # Invalid path
6 required_result 1 <<EOF
7 run_event_init() failed, ret=2
8 EOF
9 unit_test run_event_test /a/b/c list
10
11 scriptdir=$(TMPDIR="$TEST_VAR_DIR" mktemp -d)
12
13 # Empty directory
14 ok <<EOF
15 No event scripts found
16 EOF
17 unit_test run_event_test "$scriptdir" list
18
19 cat > "$scriptdir/prog" <<EOF
20 #!/bin/sh
21
22 echo hello
23 EOF
24
25 # Invalid script, doesn't end in ".script"
26 ok <<EOF
27 No event scripts found
28 EOF
29 unit_test run_event_test "$scriptdir" list
30
31 # Is not found because enabling "prog" actually looks for "prog.script"
32 ok <<EOF
33 Script enable prog completed with result=2
34 EOF
35 unit_test run_event_test "$scriptdir" enable prog
36
37 required_result 1 <<EOF
38 EOF
39 unit_test test -x "${scriptdir}/prog"
40
41 cat > "$scriptdir/11.foo.script" <<EOF
42 #!/bin/sh
43
44 echo hello
45 EOF
46
47 # Valid script
48 ok <<EOF
49 11.foo
50 EOF
51 unit_test run_event_test "$scriptdir" list
52
53 ok <<EOF
54 Script enable 11.foo completed with result=0
55 EOF
56 unit_test run_event_test "$scriptdir" enable 11.foo
57
58 ok <<EOF
59 EOF
60 unit_test test -x "${scriptdir}/11.foo.script"
61
62 ok <<EOF
63 11.foo: hello
64 Event monitor completed with result=0
65 11.foo result=0
66 EOF
67 unit_test run_event_test "$scriptdir" run 10 monitor
68
69 cat > "$scriptdir/22.bar.script" <<EOF
70 #!/bin/sh
71
72 exit 1
73 EOF
74
75 # Multiple scripts
76 ok <<EOF
77 11.foo
78 22.bar
79 EOF
80 unit_test run_event_test "$scriptdir" list
81
82 ok <<EOF
83 Script enable 22.bar completed with result=0
84 EOF
85 unit_test run_event_test "$scriptdir" enable 22.bar
86
87 ok <<EOF
88 11.foo: hello
89 Event monitor completed with result=1
90 11.foo result=0
91 22.bar result=1
92 EOF
93 unit_test run_event_test "$scriptdir" run 10 monitor
94
95 # Disable script
96 ok <<EOF
97 Script disable 22.bar completed with result=0
98 EOF
99 unit_test run_event_test "$scriptdir" disable 22.bar
100
101 required_result 1 <<EOF
102 EOF
103 unit_test test -x "${scriptdir}/22.bar.script"
104
105 ok <<EOF
106 11.foo: hello
107 Event monitor completed with result=0
108 11.foo result=0
109 22.bar result=-$(errcode ENOEXEC)
110 EOF
111 unit_test run_event_test "$scriptdir" run 10 monitor
112
113 cat > "$scriptdir/22.bar.script" <<EOF
114 #!/bin/sh
115
116 sleep 10
117 EOF
118
119 # Timed out script
120 ok <<EOF
121 Script enable 22.bar completed with result=0
122 EOF
123 unit_test run_event_test "$scriptdir" enable 22.bar
124
125 ok <<EOF
126 11.foo: hello
127 Event monitor completed with result=-$(errcode ETIMEDOUT)
128 11.foo result=0
129 22.bar result=-$(errcode ETIMEDOUT)
130 EOF
131 unit_test run_event_test "$scriptdir" run 5 monitor
132
133 rm -rf "$scriptdir"
134 exit 0