forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotrestart_test.sh
executable file
·183 lines (151 loc) · 7.88 KB
/
hotrestart_test.sh
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
source "$TEST_RUNDIR/test/integration/test_utility.sh"
# TODO(htuch): In this test script, we are duplicating work done in test_environment.cc via sed.
# Instead, we can add a simple C++ binary that links against test_environment.cc and uses the
# substitution methods provided there.
JSON_TEST_ARRAY=()
# Parameterize IPv4 and IPv6 testing.
if [[ -z "${ENVOY_IP_TEST_VERSIONS}" ]] || [[ "${ENVOY_IP_TEST_VERSIONS}" == "all" ]] \
|| [[ "${ENVOY_IP_TEST_VERSIONS}" == "v4only" ]]; then
HOT_RESTART_JSON_V4="${TEST_TMPDIR}"/hot_restart_v4.yaml
echo building ${HOT_RESTART_JSON_V4} ...
cat "${TEST_RUNDIR}"/test/config/integration/server.yaml |
sed -e "s#{{ upstream_. }}#0#g" | \
sed -e "s#{{ test_rundir }}#$TEST_RUNDIR#" | \
sed -e "s#{{ test_tmpdir }}#$TEST_TMPDIR#" | \
sed -e "s#{{ ip_loopback_address }}#127.0.0.1#" | \
sed -e "s#{{ dns_lookup_family }}#V4_ONLY#" | \
cat > "${HOT_RESTART_JSON_V4}"
JSON_TEST_ARRAY+=("${HOT_RESTART_JSON_V4}")
fi
if [[ -z "${ENVOY_IP_TEST_VERSIONS}" ]] || [[ "${ENVOY_IP_TEST_VERSIONS}" == "all" ]] \
|| [[ "${ENVOY_IP_TEST_VERSIONS}" == "v6only" ]]; then
HOT_RESTART_JSON_V6="${TEST_TMPDIR}"/hot_restart_v6.yaml
cat "${TEST_RUNDIR}"/test/config/integration/server.yaml |
sed -e "s#{{ upstream_. }}#0#g" | \
sed -e "s#{{ test_rundir }}#$TEST_RUNDIR#" | \
sed -e "s#{{ test_tmpdir }}#$TEST_TMPDIR#" | \
sed -e "s#{{ ip_loopback_address }}#::1#" | \
sed -e "s#{{ dns_lookup_family }}#v6_only#" | \
cat > "${HOT_RESTART_JSON_V6}"
JSON_TEST_ARRAY+=("${HOT_RESTART_JSON_V6}")
fi
# Also test for listening on UNIX domain sockets. We use IPv4 for the
# upstreams to avoid too much wild sedding.
HOT_RESTART_JSON_UDS="${TEST_TMPDIR}"/hot_restart_uds.yaml
SOCKET_DIR="$(mktemp -d /tmp/envoy_test_hotrestart.XXXXXX)"
cat "${TEST_RUNDIR}"/test/config/integration/server_unix_listener.yaml |
sed -e "s#{{ socket_dir }}#${SOCKET_DIR}#" | \
sed -e "s#{{ ip_loopback_address }}#127.0.0.1#" | \
cat > "${HOT_RESTART_JSON_UDS}"
JSON_TEST_ARRAY+=("${HOT_RESTART_JSON_UDS}")
# Enable this test to work with --runs_per_test
if [[ -z "${TEST_RANDOM_SEED}" ]]; then
BASE_ID=1
else
BASE_ID="${TEST_RANDOM_SEED}"
fi
echo "Hot restart test using --base-id ${BASE_ID}"
TEST_INDEX=0
for HOT_RESTART_JSON in "${JSON_TEST_ARRAY[@]}"
do
# TODO(jun03): instead of setting the base-id, the validate server should use the nop hot restart
start_test validation
check "${ENVOY_BIN}" -c "${HOT_RESTART_JSON}" --mode validate --service-cluster cluster \
--max-obj-name-len 500 --service-node node --base-id "${BASE_ID}"
# Now start the real server, hot restart it twice, and shut it all down as a basic hot restart
# sanity test.
start_test Starting epoch 0
ADMIN_ADDRESS_PATH_0="${TEST_TMPDIR}"/admin.0."${TEST_INDEX}".address
run_in_background_saving_pid "${ENVOY_BIN}" -c "${HOT_RESTART_JSON}" \
--restart-epoch 0 --base-id "${BASE_ID}" --service-cluster cluster --service-node node \
--max-obj-name-len 500 --admin-address-path "${ADMIN_ADDRESS_PATH_0}"
FIRST_SERVER_PID=$BACKGROUND_PID
start_test Updating original config listener addresses
sleep 3
UPDATED_HOT_RESTART_JSON="${TEST_TMPDIR}"/hot_restart_updated."${TEST_INDEX}".yaml
"${TEST_RUNDIR}"/tools/socket_passing "-o" "${HOT_RESTART_JSON}" "-a" "${ADMIN_ADDRESS_PATH_0}" \
"-u" "${UPDATED_HOT_RESTART_JSON}"
# Send SIGUSR1 signal to the first server, this should not kill it. Also send SIGHUP which should
# get eaten.
echo "Sending SIGUSR1/SIGHUP to first server"
kill -SIGUSR1 ${FIRST_SERVER_PID}
kill -SIGHUP ${FIRST_SERVER_PID}
sleep 3
disableHeapCheck
# To ensure that we don't accidentally change the /hot_restart_version
# string, compare it against a hard-coded string.
start_test Checking for consistency of /hot_restart_version
CLI_HOT_RESTART_VERSION=$("${ENVOY_BIN}" --hot-restart-version --base-id "${BASE_ID}" 2>&1)
EXPECTED_CLI_HOT_RESTART_VERSION="10.200.16384.127.options=capacity=16384, num_slots=8209 hash=228984379728933363 size=2654312"
check [ "${CLI_HOT_RESTART_VERSION}" = "${EXPECTED_CLI_HOT_RESTART_VERSION}" ]
start_test Checking for consistency of /hot_restart_version with --max-obj-name-len 500
CLI_HOT_RESTART_VERSION=$("${ENVOY_BIN}" --hot-restart-version --base-id "${BASE_ID}" \
--max-obj-name-len 500 2>&1)
EXPECTED_CLI_HOT_RESTART_VERSION="10.200.16384.567.options=capacity=16384, num_slots=8209 hash=228984379728933363 size=9863272"
check [ "${CLI_HOT_RESTART_VERSION}" = "${EXPECTED_CLI_HOT_RESTART_VERSION}" ]
start_test Checking for match of --hot-restart-version and admin /hot_restart_version
ADMIN_ADDRESS_0=$(cat "${ADMIN_ADDRESS_PATH_0}")
echo fetching hot restart version from http://${ADMIN_ADDRESS_0}/hot_restart_version ...
ADMIN_HOT_RESTART_VERSION=$(curl -sg http://${ADMIN_ADDRESS_0}/hot_restart_version)
CLI_HOT_RESTART_VERSION=$("${ENVOY_BIN}" --hot-restart-version --base-id "${BASE_ID}" \
--max-obj-name-len 500 2>&1)
check [ "${ADMIN_HOT_RESTART_VERSION}" = "${CLI_HOT_RESTART_VERSION}" ]
start_test Checking for hot-restart-version mismatch when max-obj-name-len differs
CLI_HOT_RESTART_VERSION=$("${ENVOY_BIN}" --hot-restart-version --base-id "${BASE_ID}" \
--max-obj-name-len 1234 2>&1)
check [ "${ADMIN_HOT_RESTART_VERSION}" != "${CLI_HOT_RESTART_VERSION}" ]
start_test Checking for hot-start-version mismatch when max-stats differs
CLI_HOT_RESTART_VERSION=$("${ENVOY_BIN}" --hot-restart-version --base-id "${BASE_ID}" \
--max-stats 12345 2>&1)
check [ "${ADMIN_HOT_RESTART_VERSION}" != "${CLI_HOT_RESTART_VERSION}" ]
enableHeapCheck
start_test Starting epoch 1
ADMIN_ADDRESS_PATH_1="${TEST_TMPDIR}"/admin.1."${TEST_INDEX}".address
run_in_background_saving_pid "${ENVOY_BIN}" -c "${UPDATED_HOT_RESTART_JSON}" \
--restart-epoch 1 --base-id "${BASE_ID}" --service-cluster cluster --service-node node \
--max-obj-name-len 500 --admin-address-path "${ADMIN_ADDRESS_PATH_1}"
SECOND_SERVER_PID=$BACKGROUND_PID
# Wait for stat flushing
sleep 7
start_test Checking that listener addresses have not changed
HOT_RESTART_JSON_1="${TEST_TMPDIR}"/hot_restart.1."${TEST_INDEX}".yaml
"${TEST_RUNDIR}"/tools/socket_passing "-o" "${UPDATED_HOT_RESTART_JSON}" "-a" "${ADMIN_ADDRESS_PATH_1}" \
"-u" "${HOT_RESTART_JSON_1}"
CONFIG_DIFF=$(diff "${UPDATED_HOT_RESTART_JSON}" "${HOT_RESTART_JSON_1}")
[[ -z "${CONFIG_DIFF}" ]]
ADMIN_ADDRESS_PATH_2="${TEST_TMPDIR}"/admin.2."${TEST_INDEX}".address
start_test Starting epoch 2
run_in_background_saving_pid "${ENVOY_BIN}" -c "${UPDATED_HOT_RESTART_JSON}" \
--restart-epoch 2 --base-id "${BASE_ID}" --service-cluster cluster --service-node node \
--max-obj-name-len 500 --admin-address-path "${ADMIN_ADDRESS_PATH_2}"
THIRD_SERVER_PID=$BACKGROUND_PID
sleep 3
start_test Checking that listener addresses have not changed
HOT_RESTART_JSON_2="${TEST_TMPDIR}"/hot_restart.2."${TEST_INDEX}".yaml
"${TEST_RUNDIR}"/tools/socket_passing "-o" "${UPDATED_HOT_RESTART_JSON}" "-a" "${ADMIN_ADDRESS_PATH_2}" \
"-u" "${HOT_RESTART_JSON_2}"
CONFIG_DIFF=$(diff "${UPDATED_HOT_RESTART_JSON}" "${HOT_RESTART_JSON_2}")
[[ -z "${CONFIG_DIFF}" ]]
# First server should already be gone.
start_test Waiting for epoch 0
wait ${FIRST_SERVER_PID}
[[ $? == 0 ]]
#Send SIGUSR1 signal to the second server, this should not kill it
start_test Sending SIGUSR1 to the second server
kill -SIGUSR1 ${SECOND_SERVER_PID}
sleep 3
# Now term the last server, and the other one should exit also.
start_test Killing and waiting for epoch 2
kill ${THIRD_SERVER_PID}
wait ${THIRD_SERVER_PID}
[[ $? == 0 ]]
start_test Waiting for epoch 1
wait ${SECOND_SERVER_PID}
[[ $? == 0 ]]
TEST_INDEX=$((TEST_INDEX+1))
done
start_test disabling hot_restart by command line.
CLI_HOT_RESTART_VERSION=$("${ENVOY_BIN}" --hot-restart-version --disable-hot-restart 2>&1)
check [ "disabled" = "${CLI_HOT_RESTART_VERSION}" ]
echo "PASS"