summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/UNIT/cunit/tmon_test_002.sh
blob: e4118a3d09af81c02b58f0477f659b89eb4fd42a (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh

. "${TEST_SCRIPTS_DIR}/unit.sh"

epipe=$(errcode EPIPE)
etimedout=$(errcode ETIMEDOUT)
edom=$(errcode EDOM)

test_cases()
{
	test_case "no packets, sender exits, 3s timeout"
	ok <<EOF
WRITER OK
READER ERR=$epipe
EOF
	unit_test tmon_test "" false 3 false

	test_case "no packets, sender exits, 3s timeout, close ok"
	ok <<EOF
WRITER OK
READER OK
EOF
	unit_test tmon_test "" true 3 false

	test_case "Exit packet @ 1s, no timeout"
	ok <<EOF
READER OK
WRITER OK
EOF
	unit_test tmon_test "0" false 0 false

	test_case "errno 7 packet @ 1s, no timeout"
	ok <<EOF
READER ERR=7
WRITER OK
EOF
	unit_test tmon_test "7" false 0 false

	test_case "errno 110 packet @ 1s, no timeout"
	ok <<EOF
READER ERR=110
WRITER OK
EOF
	unit_test tmon_test "#110" false 0 false

	test_case "errno 0 error causes EDOM @ 1s, no timeout"
	ok <<EOF
WRITER ERR=$edom
READER ERR=$epipe
EOF
	unit_test tmon_test "#0;" false 0 false

	test_case "errno -1 error causes EDOM @ 1s, no timeout"
	ok <<EOF
WRITER ERR=$edom
READER ERR=$epipe
EOF
	unit_test tmon_test "#-1;" false 0 false

	test_case "errno 70000 error causes EDOM @ 1s, no timeout"
	ok <<EOF
WRITER ERR=$edom
READER ERR=$epipe
EOF
	unit_test tmon_test "#70000;!0" false 0 false

	test_case "Exit packet @ 3s, no timeout"
	ok <<EOF
READER OK
WRITER OK
EOF
	unit_test tmon_test "..0" false 0 false

	test_case "errno 7 packet @ 3s, no timeout"
	ok <<EOF
READER ERR=7
WRITER OK
EOF
	unit_test tmon_test "..7" false 0 false

	test_case "no packets for 5s, 3s timeout"
	ok <<EOF
READER ERR=$etimedout
WRITER OK
EOF
	unit_test tmon_test "....." false 3 false

	test_case "no packets for 5s, 3s timeout, timeout ok"
	ok <<EOF
READER OK
WRITER OK
EOF
	unit_test tmon_test "....." false 3 true

	test_case "4 pings then exit, 3s timeout"
	ok <<EOF
PING
PING
PING
PING
READER OK
WRITER OK
EOF
	unit_test tmon_test "!!!!0" false 3 false

	test_case "ASCII Hello, errno 7, 3s timeout"
	ok <<EOF
ASCII H
ASCII e
ASCII l
ASCII l
ASCII o
READER ERR=7
WRITER OK
EOF
	unit_test tmon_test "Hello7" false 3 false

	test_case "Hi there! 3s timeout"
	ok <<EOF
ASCII H
ASCII i
CUSTOM 0x20
ASCII t
ASCII h
ASCII e
ASCII r
ASCII e
PING
WRITER OK
READER ERR=$epipe
EOF
	unit_test tmon_test "Hi there!" false 3 false
}

echo "PASS #1: Run test cases in default mode"
test_cases

echo
echo "=================================================="

echo "PASS #2: Run test cases in write-skip mode"
CTDB_TEST_TMON_WRITE_SKIP_MODE=1 test_cases