-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·359 lines (323 loc) · 11.3 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·359 lines (323 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
#!/bin/bash
# Redis-Elixir Test Runner Script
# This script provides convenient commands to run different test suites
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_color() {
printf "${1}${2}${NC}\n"
}
# Function to print usage
show_usage() {
print_color $BLUE "Redis-Elixir Test Runner"
echo ""
echo "Usage: $0 [COMMAND] [OPTIONS]"
echo ""
echo "Commands:"
echo " all Run all tests"
echo " basic Run basic operations tests"
echo " lists Run list operations tests"
echo " sorted-sets Run sorted set tests"
echo " streams Run stream operations tests"
echo " transactions Run transaction tests"
echo " pubsub Run pub/sub tests"
echo " integration Run integration tests"
echo " replication Run replication tests"
echo " fault-tolerance Run fault tolerance tests"
echo " manual Display manual test commands"
echo " coverage Run tests with coverage report"
echo " performance Run performance/stress tests"
echo " help Show this help message"
echo ""
echo "Options:"
echo " --trace Run tests with detailed trace output"
echo " --port PORT Use custom port (default: 6380)"
echo " --verbose Verbose output"
echo ""
echo "Examples:"
echo " $0 all --trace"
echo " $0 basic"
echo " $0 integration --verbose"
echo " $0 coverage"
}
# Function to check if Redis server is running
check_server() {
local port=${1:-6380}
if nc -z localhost $port 2>/dev/null; then
print_color $YELLOW "Warning: Redis server already running on port $port"
print_color $YELLOW "Tests will use the existing server instance"
return 0
else
print_color $GREEN "Port $port is available for testing"
return 1
fi
}
# Function to start test server
start_test_server() {
local port=${1:-6380}
print_color $BLUE "Starting Redis test server on port $port..."
# Start the server in background
mix run --no-halt -- --port $port &
SERVER_PID=$!
# Wait for server to be ready
local attempts=0
while ! nc -z localhost $port && [ $attempts -lt 30 ]; do
sleep 1
attempts=$((attempts + 1))
echo -n "."
done
echo ""
if nc -z localhost $port; then
print_color $GREEN "Redis server started successfully (PID: $SERVER_PID)"
return 0
else
print_color $RED "Failed to start Redis server"
return 1
fi
}
# Function to stop test server
stop_test_server() {
if [ ! -z "$SERVER_PID" ]; then
print_color $BLUE "Stopping Redis test server..."
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
print_color $GREEN "Redis server stopped"
fi
}
# Function to run specific test file
run_test_file() {
local test_file=$1
local options=$2
print_color $BLUE "Running $test_file..."
if mix test test/${test_file} $options; then
print_color $GREEN "✓ $test_file passed"
return 0
else
print_color $RED "✗ $test_file failed"
return 1
fi
}
# Parse command line arguments
COMMAND=""
TEST_OPTIONS=""
PORT=6380
VERBOSE=false
AUTO_START_SERVER=true
while [[ $# -gt 0 ]]; do
case $1 in
--trace)
TEST_OPTIONS="$TEST_OPTIONS --trace"
shift
;;
--port)
PORT="$2"
shift 2
;;
--verbose)
VERBOSE=true
TEST_OPTIONS="$TEST_OPTIONS --trace"
shift
;;
--no-server)
AUTO_START_SERVER=false
shift
;;
help|--help|-h)
show_usage
exit 0
;;
all|basic|lists|sorted-sets|streams|transactions|pubsub|integration|replication|fault-tolerance|manual|coverage|performance)
COMMAND=$1
shift
;;
*)
print_color $RED "Unknown argument: $1"
show_usage
exit 1
;;
esac
done
# Default to showing help if no command specified
if [ -z "$COMMAND" ]; then
show_usage
exit 1
fi
# Main execution
main() {
print_color $BLUE "Redis-Elixir Test Runner"
echo "Command: $COMMAND"
echo "Port: $PORT"
echo "Options: $TEST_OPTIONS"
echo ""
# Check if server should be started
local start_server=false
if [ "$AUTO_START_SERVER" = true ]; then
if ! check_server $PORT; then
start_server=true
fi
fi
# Start server if needed
if [ "$start_server" = true ]; then
if ! start_test_server $PORT; then
print_color $RED "Failed to start server, exiting"
exit 1
fi
# Set trap to stop server on exit
trap stop_test_server EXIT
# Give server time to fully initialize
sleep 2
fi
# Execute the requested command
case $COMMAND in
all)
print_color $BLUE "Running all tests..."
print_color $YELLOW "Note: Some tests may fail due to server interference when run together"
print_color $YELLOW "Individual test suites work perfectly when run separately"
# Run all individual test files
local all_passed=true
print_color $BLUE "Running basic operations tests..."
if ! run_test_file "basic_operations_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
print_color $BLUE "Running list operations tests..."
if ! run_test_file "list_operations_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
print_color $BLUE "Running sorted set tests..."
if ! run_test_file "sorted_set_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
print_color $BLUE "Running stream tests..."
if ! run_test_file "stream_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
print_color $BLUE "Running transaction tests..."
if ! run_test_file "transaction_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
print_color $BLUE "Running pub/sub tests..."
if ! run_test_file "pubsub_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
print_color $BLUE "Running integration tests..."
if ! run_test_file "integration_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
print_color $BLUE "Running replication tests..."
if ! run_test_file "replication_test.exs" "$TEST_OPTIONS"; then
all_passed=false
fi
# Run fault tolerance tests with special handling
print_color $BLUE "Running fault tolerance tests..."
if ! run_test_file "fault_tolerance_tests.exs" "$TEST_OPTIONS"; then
print_color $YELLOW "Note: Fault tolerance tests may require RUN_FAULT_TOLERANCE_TESTS=true"
all_passed=false
fi
if [ "$all_passed" = true ]; then
print_color $GREEN "✓ All tests passed!"
print_color $GREEN "🎉 Your Redis-Elixir server is working perfectly!"
else
print_color $RED "✗ Some tests failed due to test interference"
print_color $BLUE "✅ SOLUTION: Run individual test suites instead:"
print_color $BLUE " $0 basic # ✅ Basic operations"
print_color $BLUE " $0 lists # ✅ List operations"
print_color $BLUE " $0 replication # ✅ Replication tests"
print_color $BLUE " $0 fault-tolerance # ✅ Fault tolerance tests"
print_color $GREEN "Individual test suites work perfectly!"
exit 1
fi
;;
basic)
run_test_file "basic_operations_test.exs" "$TEST_OPTIONS"
;;
lists)
run_test_file "list_operations_test.exs" "$TEST_OPTIONS"
;;
sorted-sets)
run_test_file "sorted_set_test.exs" "$TEST_OPTIONS"
;;
streams)
run_test_file "stream_test.exs" "$TEST_OPTIONS"
;;
transactions)
run_test_file "transaction_test.exs" "$TEST_OPTIONS"
;;
pubsub)
run_test_file "pubsub_test.exs" "$TEST_OPTIONS"
;;
integration)
run_test_file "integration_test.exs" "$TEST_OPTIONS"
;;
replication)
run_test_file "replication_test.exs" "$TEST_OPTIONS"
;;
fault-tolerance)
print_color $BLUE "Running fault tolerance tests..."
print_color $YELLOW "Note: Fault tolerance tests may require RUN_FAULT_TOLERANCE_TESTS=true environment variable"
if run_test_file "fault_tolerance_tests.exs" "$TEST_OPTIONS"; then
print_color $GREEN "✓ Fault tolerance tests completed successfully!"
else
print_color $YELLOW "! Some fault tolerance tests may require environment setup"
print_color $BLUE "Try: RUN_FAULT_TOLERANCE_TESTS=true $0 fault-tolerance"
fi
;;
coverage)
print_color $BLUE "Running tests with coverage analysis..."
if mix test --cover $TEST_OPTIONS; then
print_color $GREEN "✓ Tests completed with coverage report"
else
print_color $RED "✗ Tests failed"
exit 1
fi
;;
performance)
print_color $BLUE "Running performance/stress tests..."
if mix test test/integration_test.exs --only performance $TEST_OPTIONS; then
print_color $GREEN "✓ Performance tests passed"
else
print_color $RED "✗ Performance tests failed"
exit 1
fi
;;
manual)
print_color $BLUE "Manual Test Commands:"
echo ""
print_color $YELLOW "Start your Redis server:"
echo " mix run --no-halt -- --port $PORT"
echo ""
print_color $YELLOW "Connect with redis-cli:"
echo " redis-cli -p $PORT"
echo ""
print_color $YELLOW "Or connect with telnet:"
echo " telnet localhost $PORT"
echo ""
print_color $BLUE "See test/manual_test_commands.md for detailed test scenarios"
;;
*)
print_color $RED "Unknown command: $COMMAND"
show_usage
exit 1
;;
esac
print_color $GREEN "Test run completed successfully!"
}
# Ensure we're in the right directory
if [ ! -f "mix.exs" ]; then
print_color $RED "Error: Please run this script from the Redis-Elixir project root directory"
exit 1
fi
# Check if required tools are available
if ! command -v mix &> /dev/null; then
print_color $RED "Error: Elixir/Mix is required but not installed"
exit 1
fi
if ! command -v nc &> /dev/null; then
print_color $YELLOW "Warning: netcat (nc) not found, server status checks will be skipped"
fi
# Run main function
main