Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·363 lines (329 loc) · 11.3 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·363 lines (329 loc) · 11.3 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/usr/bin/env bash
set -euo pipefail
# ==============================================================================
# PgVisor: Unified Integration Test Suite Runner
#
# Supports sequential execution (default) and concurrent/parallel execution
# via --parallel or -j <N>. All output is strictly clean plain text.
# ==============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="${SCRIPT_DIR}"
TEST_DIR="${REPO_ROOT}/tests"
LOG_DIR="${TEST_DIR}/.logs"
mkdir -p "${LOG_DIR}"
PARALLEL=false
MAX_JOBS=2
BUILD_IMAGES=false
SWARM_ONLY=false
FAIL_FAST=false
CI_MODE=false
if [[ "${CI:-}" == "true" || "${GITHUB_ACTIONS:-}" == "true" ]]; then
CI_MODE=true
fi
# Parse CLI arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--build)
BUILD_IMAGES=true
shift
;;
--parallel)
PARALLEL=true
shift
;;
-j)
PARALLEL=true
MAX_JOBS="$2"
shift 2
;;
--jobs=*)
PARALLEL=true
MAX_JOBS="${1#*=}"
shift
;;
--swarm)
SWARM_ONLY=true
shift
;;
--fail-fast)
FAIL_FAST=true
shift
;;
--ci)
CI_MODE=true
shift
;;
-h|--help)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --build Pre-build test Docker images before running tests"
echo " --parallel Run tests concurrently (default max jobs: 2)"
echo " -j, --jobs=N Set max parallel jobs (implies --parallel)"
echo " --swarm Run Docker Swarm DinD tests only"
echo " --fail-fast Stop running remaining tests immediately after the first failure"
echo " --ci Print failed test logs directly to console (auto in CI)"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown argument: $1"
echo "Run with --help for usage."
exit 1
;;
esac
done
if [[ "${BUILD_IMAGES}" == "true" ]]; then
echo "Building PgVisor Docker image (dreamoutbox/pgvisor:latest)..."
"${REPO_ROOT}/dev-build-image.sh"
fi
# Ensure compose profiles are up to date
"${REPO_ROOT}/scripts/generate-test-composes.sh" > /dev/null
if [[ "${SWARM_ONLY}" == "true" ]]; then
TEST_SCRIPTS=(
"test-swarm-crud.sh"
"test-swarm-failover.sh"
"test-swarm-switchover.sh"
"test-swarm-add-node.sh"
)
else
TEST_SCRIPTS=(
"test-cluster-crud.sh"
"test-backup-restore.sh"
"test-incremental-pitr.sh"
"test-failover.sh"
"test-auto-rejoin.sh"
"test-rejoin-fenced.sh"
"test-add-node.sh"
"test-switchover.sh"
"test-users-permissions.sh"
"test-transaction.sh"
"test-routing.sh"
"test-audit-logs.sh"
"test-double-failure.sh"
"test-proxy-failover.sh"
"test-metrics.sh"
"test-timeline-divergence.sh"
"test-node-lifecycle.sh"
"test-restart-leader.sh"
"test-promoted-restore.sh"
"test-cluster-auth.sh"
"test-tls.sh"
"test-dashboard-tables-nodes.sh"
)
fi
TOTAL_TESTS="${#TEST_SCRIPTS[@]}"
START_TIME=$(date +%s)
echo "============================================================="
if [[ "${PARALLEL}" == "true" ]]; then
echo " PgVisor Integration Test Suite (Parallel: ${MAX_JOBS} jobs)"
else
echo " PgVisor Integration Test Suite (Sequential Execution)"
fi
echo "============================================================="
echo "Total tests to run: ${TOTAL_TESTS}"
echo "Log directory: ${LOG_DIR}"
echo ""
declare -A TEST_STATUS
declare -A TEST_DURATION
run_single_test() {
local test_name="$1"
local script_path="${TEST_DIR}/${test_name}"
local log_file="${LOG_DIR}/${test_name%.sh}.log"
local t_start
local t_end
local duration
local rc
t_start=$(date +%s)
if bash "${script_path}" > "${log_file}" 2>&1; then
rc=0
else
rc=$?
fi
t_end=$(date +%s)
duration=$((t_end - t_start))
if [[ ${rc} -eq 0 ]]; then
echo "[PASSED ] ${test_name} (${duration}s)"
echo "PASS:${duration}" > "${LOG_DIR}/${test_name%.sh}.result"
return 0
else
echo "[FAILED ] ${test_name} (${duration}s, exit: ${rc}) - See ${log_file}"
echo "FAIL:${duration}:${rc}" > "${LOG_DIR}/${test_name%.sh}.result"
return "${rc}"
fi
}
has_any_failure() {
grep -q "^FAIL:" "${LOG_DIR}"/*.result 2>/dev/null
}
# Clean old result markers
rm -f "${LOG_DIR}"/*.result
# Determine initial concurrency limit
concurrency=1
if [[ "${PARALLEL}" == "true" ]]; then
concurrency="${MAX_JOBS}"
fi
# Print initial status for all tests upfront
for ((i=0; i<TOTAL_TESTS; i++)); do
if [[ ${i} -lt ${concurrency} ]]; then
echo "[STARTED] ${TEST_SCRIPTS[i]}"
else
echo "[WAIT] ${TEST_SCRIPTS[i]}"
fi
done
if [[ "${PARALLEL}" == "true" ]]; then
# Concurrency control using background jobs and job pool
running=0
for ((i=0; i<TOTAL_TESTS; i++)); do
if [[ "${FAIL_FAST}" == "true" ]] && has_any_failure; then
echo "[FAIL-FAST] Failure detected, skipping remaining queued tests..."
break
fi
test_file="${TEST_SCRIPTS[i]}"
# If this test was waiting initially, print [STARTED] as it launches now
if [[ ${i} -ge ${concurrency} ]]; then
echo "[STARTED] ${test_file}"
fi
( run_single_test "${test_file}" || true ) &
running=$((running + 1))
if [[ ${running} -ge ${MAX_JOBS} ]]; then
wait -n 2>/dev/null || wait
running=$((running - 1))
if [[ "${FAIL_FAST}" == "true" ]] && has_any_failure; then
echo "[FAIL-FAST] Failure detected, waiting for active jobs to finish cleanup..."
break
fi
fi
done
wait
else
# Sequential execution
for ((i=0; i<TOTAL_TESTS; i++)); do
test_file="${TEST_SCRIPTS[i]}"
if [[ ${i} -ge ${concurrency} ]]; then
echo "[STARTED] ${test_file}"
fi
if ! run_single_test "${test_file}"; then
if [[ "${FAIL_FAST}" == "true" ]]; then
echo "[FAIL-FAST] Stopping test suite after first failure (${test_file})."
break
fi
fi
done
fi
TOTAL_END=$(date +%s)
TOTAL_DURATION=$((TOTAL_END - START_TIME))
# Collate results
PASSED_COUNT=0
FAILED_COUNT=0
SKIPPED_COUNT=0
FAILED_TESTS=()
FAILED_LOG_ENTRIES=()
echo ""
echo "============================================================="
echo " Test Results Summary"
echo "============================================================="
for test_file in "${TEST_SCRIPTS[@]}"; do
res_file="${LOG_DIR}/${test_file%.sh}.result"
log_file="${LOG_DIR}/${test_file%.sh}.log"
if [[ -f "${res_file}" ]]; then
raw=$(cat "${res_file}")
status=$(echo "${raw}" | cut -d':' -f1)
dur=$(echo "${raw}" | cut -d':' -f2)
if [[ "${status}" == "PASS" ]]; then
printf " %-26s : PASSED (%ds)\n" "${test_file}" "${dur}"
PASSED_COUNT=$((PASSED_COUNT + 1))
else
printf " %-26s : FAILED (%ds) -> %s\n" "${test_file}" "${dur}" "${log_file}"
FAILED_COUNT=$((FAILED_COUNT + 1))
FAILED_TESTS+=("${test_file} (${dur}s): ${log_file}")
FAILED_LOG_ENTRIES+=("${test_file}|${log_file}|${dur}")
fi
elif [[ "${FAIL_FAST}" == "true" ]]; then
printf " %-26s : SKIPPED (fail-fast)\n" "${test_file}"
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
else
printf " %-26s : UNKNOWN -> %s\n" "${test_file}" "${log_file}"
FAILED_COUNT=$((FAILED_COUNT + 1))
FAILED_TESTS+=("${test_file} (unknown): ${log_file}")
FAILED_LOG_ENTRIES+=("${test_file}|${log_file}|unknown")
fi
done
echo "============================================================="
echo "Total: ${TOTAL_TESTS}"
echo "Passed: ${PASSED_COUNT}"
echo "Failed: ${FAILED_COUNT}"
if [[ ${SKIPPED_COUNT} -gt 0 ]]; then
echo "Skipped: ${SKIPPED_COUNT}"
fi
echo "Duration: ${TOTAL_DURATION}s"
echo "============================================================="
if [[ ${FAILED_COUNT} -eq 0 ]]; then
echo "All tests passed successfully!"
exit 0
else
echo "Failed Tests (${FAILED_COUNT}):"
for failed_item in "${FAILED_TESTS[@]}"; do
echo " - ${failed_item}"
done
echo "============================================================="
if [[ "${CI_MODE}" == "true" ]]; then
echo ""
echo "============================================================="
echo " CI Error Details (${FAILED_COUNT} test(s) failed)"
echo "============================================================="
for entry in "${FAILED_LOG_ENTRIES[@]}"; do
t_name=$(echo "${entry}" | cut -d'|' -f1)
t_log=$(echo "${entry}" | cut -d'|' -f2)
t_dur=$(echo "${entry}" | cut -d'|' -f3)
if [[ "${t_dur}" != "unknown" ]]; then
dur_info="duration: ${t_dur}s"
else
dur_info="duration: unknown"
fi
echo ""
echo "============================================================="
echo "====== BEGIN OF ${t_name} (${dur_info}) ======"
echo "============================================================="
if [[ -f "${t_log}" ]]; then
cat "${t_log}"
else
echo "(Log file not found: ${t_log})"
fi
echo ""
echo "============================================================="
echo "====== END OF ${t_name} ======"
echo "============================================================="
done
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]] && ( touch "${GITHUB_STEP_SUMMARY}" ) 2>/dev/null; then
{
echo "### ❌ Failed Integration Tests (${FAILED_COUNT})"
echo ""
for entry in "${FAILED_LOG_ENTRIES[@]}"; do
t_name=$(echo "${entry}" | cut -d'|' -f1)
t_log=$(echo "${entry}" | cut -d'|' -f2)
t_dur=$(echo "${entry}" | cut -d'|' -f3)
if [[ "${t_dur}" != "unknown" ]]; then
dur_info="${t_dur}s"
else
dur_info="unknown"
fi
echo "<details open>"
echo "<summary><b>Failed: <code>${t_name}</code> (${dur_info})</b></summary>"
echo ""
echo '```text'
if [[ -f "${t_log}" ]]; then
cat "${t_log}"
else
echo "(Log file not found: ${t_log})"
fi
echo '```'
echo ""
echo "</details>"
echo ""
done
} >> "${GITHUB_STEP_SUMMARY}"
fi
fi
echo "${FAILED_COUNT} test(s) failed. Check logs above."
exit 1
fi