aboutsummaryrefslogtreecommitdiff
path: root/seaweedfs-rdma-sidecar/scripts/run-integration-tests.sh
blob: a9e5bd6441430b67d3859cf3f856c05a354805d0 (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
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
#!/bin/bash

set -euo pipefail

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Configuration
MOUNT_POINT=${MOUNT_POINT:-"/mnt/seaweedfs"}
FILER_ADDR=${FILER_ADDR:-"seaweedfs-filer:8888"}
RDMA_SIDECAR_ADDR=${RDMA_SIDECAR_ADDR:-"rdma-sidecar:8081"}
TEST_RESULTS_DIR=${TEST_RESULTS_DIR:-"/test-results"}

# Test counters
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0

# Create results directory
mkdir -p "$TEST_RESULTS_DIR"

# Log file
LOG_FILE="$TEST_RESULTS_DIR/integration-test.log"
exec > >(tee -a "$LOG_FILE")
exec 2>&1

echo -e "${BLUE}๐Ÿงช SEAWEEDFS RDMA MOUNT INTEGRATION TESTS${NC}"
echo "=========================================="
echo "Mount Point: $MOUNT_POINT"
echo "Filer Address: $FILER_ADDR"
echo "RDMA Sidecar: $RDMA_SIDECAR_ADDR"
echo "Results Directory: $TEST_RESULTS_DIR"
echo "Log File: $LOG_FILE"
echo ""

# Function to run a test
run_test() {
    local test_name=$1
    local test_command=$2
    
    echo -e "${BLUE}๐Ÿ”ฌ Running test: $test_name${NC}"
    ((TOTAL_TESTS++))
    
    if eval "$test_command"; then
        echo -e "${GREEN}โœ… PASSED: $test_name${NC}"
        ((PASSED_TESTS++))
        echo "PASS" > "$TEST_RESULTS_DIR/${test_name}.result"
    else
        echo -e "${RED}โŒ FAILED: $test_name${NC}"
        ((FAILED_TESTS++))
        echo "FAIL" > "$TEST_RESULTS_DIR/${test_name}.result"
    fi
    echo ""
}

# Function to wait for mount to be ready
wait_for_mount() {
    local max_attempts=30
    local attempt=1
    
    echo -e "${BLUE}โณ Waiting for mount to be ready...${NC}"
    
    while [[ $attempt -le $max_attempts ]]; do
        if mountpoint -q "$MOUNT_POINT" 2>/dev/null && ls "$MOUNT_POINT" >/dev/null 2>&1; then
            echo -e "${GREEN}โœ… Mount is ready${NC}"
            return 0
        fi
        echo "   Attempt $attempt/$max_attempts..."
        sleep 2
        ((attempt++))
    done
    
    echo -e "${RED}โŒ Mount failed to be ready${NC}"
    return 1
}

# Function to check RDMA sidecar
check_rdma_sidecar() {
    echo -e "${BLUE}๐Ÿ” Checking RDMA sidecar status...${NC}"
    
    local response
    if response=$(curl -s "http://$RDMA_SIDECAR_ADDR/health" 2>/dev/null); then
        echo "RDMA Sidecar Health: $response"
        return 0
    else
        echo -e "${RED}โŒ RDMA sidecar is not responding${NC}"
        return 1
    fi
}

# Test 1: Mount Point Accessibility
test_mount_accessibility() {
    mountpoint -q "$MOUNT_POINT" && ls "$MOUNT_POINT" >/dev/null
}

# Test 2: Basic File Operations
test_basic_file_operations() {
    local test_file="$MOUNT_POINT/test_basic_ops.txt"
    local test_content="Hello, RDMA World! $(date)"
    
    # Write test
    echo "$test_content" > "$test_file" || return 1
    
    # Read test
    local read_content
    read_content=$(cat "$test_file") || return 1
    
    # Verify content
    [[ "$read_content" == "$test_content" ]] || return 1
    
    # Cleanup
    rm -f "$test_file"
    
    return 0
}

# Test 3: Large File Operations
test_large_file_operations() {
    local test_file="$MOUNT_POINT/test_large_file.dat"
    local size_mb=10
    
    # Create large file
    dd if=/dev/zero of="$test_file" bs=1M count=$size_mb 2>/dev/null || return 1
    
    # Verify size
    local actual_size
    actual_size=$(stat -c%s "$test_file" 2>/dev/null) || return 1
    local expected_size=$((size_mb * 1024 * 1024))
    
    [[ "$actual_size" -eq "$expected_size" ]] || return 1
    
    # Read test
    dd if="$test_file" of=/dev/null bs=1M 2>/dev/null || return 1
    
    # Cleanup
    rm -f "$test_file"
    
    return 0
}

# Test 4: Directory Operations
test_directory_operations() {
    local test_dir="$MOUNT_POINT/test_directory"
    local test_file="$test_dir/test_file.txt"
    
    # Create directory
    mkdir -p "$test_dir" || return 1
    
    # Create file in directory
    echo "Directory test" > "$test_file" || return 1
    
    # List directory
    ls "$test_dir" | grep -q "test_file.txt" || return 1
    
    # Read file
    grep -q "Directory test" "$test_file" || return 1
    
    # Cleanup
    rm -rf "$test_dir"
    
    return 0
}

# Test 5: Multiple File Operations
test_multiple_files() {
    local test_dir="$MOUNT_POINT/test_multiple"
    local num_files=20
    
    mkdir -p "$test_dir" || return 1
    
    # Create multiple files
    for i in $(seq 1 $num_files); do
        echo "File $i content" > "$test_dir/file_$i.txt" || return 1
    done
    
    # Verify all files exist and have correct content
    for i in $(seq 1 $num_files); do
        [[ -f "$test_dir/file_$i.txt" ]] || return 1
        grep -q "File $i content" "$test_dir/file_$i.txt" || return 1
    done
    
    # List files
    local file_count
    file_count=$(ls "$test_dir" | wc -l) || return 1
    [[ "$file_count" -eq "$num_files" ]] || return 1
    
    # Cleanup
    rm -rf "$test_dir"
    
    return 0
}

# Test 6: RDMA Statistics
test_rdma_statistics() {
    local stats_response
    stats_response=$(curl -s "http://$RDMA_SIDECAR_ADDR/stats" 2>/dev/null) || return 1
    
    # Check if response contains expected fields
    echo "$stats_response" | jq -e '.rdma_enabled' >/dev/null || return 1
    echo "$stats_response" | jq -e '.total_reads' >/dev/null || return 1
    
    return 0
}

# Test 7: Performance Baseline
test_performance_baseline() {
    local test_file="$MOUNT_POINT/performance_test.dat"
    local size_mb=50
    
    # Write performance test
    local write_start write_end write_time
    write_start=$(date +%s%N)
    dd if=/dev/zero of="$test_file" bs=1M count=$size_mb 2>/dev/null || return 1
    write_end=$(date +%s%N)
    write_time=$(((write_end - write_start) / 1000000)) # Convert to milliseconds
    
    # Read performance test
    local read_start read_end read_time
    read_start=$(date +%s%N)
    dd if="$test_file" of=/dev/null bs=1M 2>/dev/null || return 1
    read_end=$(date +%s%N)
    read_time=$(((read_end - read_start) / 1000000)) # Convert to milliseconds
    
    # Log performance metrics
    echo "Performance Metrics:" > "$TEST_RESULTS_DIR/performance.txt"
    echo "Write Time: ${write_time}ms for ${size_mb}MB" >> "$TEST_RESULTS_DIR/performance.txt"
    echo "Read Time: ${read_time}ms for ${size_mb}MB" >> "$TEST_RESULTS_DIR/performance.txt"
    echo "Write Throughput: $(bc <<< "scale=2; $size_mb * 1000 / $write_time") MB/s" >> "$TEST_RESULTS_DIR/performance.txt"
    echo "Read Throughput: $(bc <<< "scale=2; $size_mb * 1000 / $read_time") MB/s" >> "$TEST_RESULTS_DIR/performance.txt"
    
    # Cleanup
    rm -f "$test_file"
    
    # Performance test always passes (it's just for metrics)
    return 0
}

# Main test execution
main() {
    echo -e "${BLUE}๐Ÿš€ Starting integration tests...${NC}"
    echo ""
    
    # Wait for mount to be ready
    if ! wait_for_mount; then
        echo -e "${RED}โŒ Mount is not ready, aborting tests${NC}"
        exit 1
    fi
    
    # Check RDMA sidecar
    check_rdma_sidecar || echo -e "${YELLOW}โš ๏ธ  RDMA sidecar check failed, continuing with tests${NC}"
    
    echo ""
    echo -e "${BLUE}๐Ÿ“‹ Running test suite...${NC}"
    echo ""
    
    # Run all tests
    run_test "mount_accessibility" "test_mount_accessibility"
    run_test "basic_file_operations" "test_basic_file_operations"
    run_test "large_file_operations" "test_large_file_operations"
    run_test "directory_operations" "test_directory_operations"
    run_test "multiple_files" "test_multiple_files"
    run_test "rdma_statistics" "test_rdma_statistics"
    run_test "performance_baseline" "test_performance_baseline"
    
    # Generate test summary
    echo -e "${BLUE}๐Ÿ“Š TEST SUMMARY${NC}"
    echo "==============="
    echo "Total Tests: $TOTAL_TESTS"
    echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}"
    echo -e "Failed: ${RED}$FAILED_TESTS${NC}"
    
    if [[ $FAILED_TESTS -eq 0 ]]; then
        echo -e "${GREEN}๐ŸŽ‰ ALL TESTS PASSED!${NC}"
        echo "SUCCESS" > "$TEST_RESULTS_DIR/overall.result"
        exit 0
    else
        echo -e "${RED}๐Ÿ’ฅ SOME TESTS FAILED!${NC}"
        echo "FAILURE" > "$TEST_RESULTS_DIR/overall.result"
        exit 1
    fi
}

# Run main function
main "$@"