run-integration-tests.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #!/bin/bash
  2. set -euo pipefail
  3. # Colors for output
  4. RED='\033[0;31m'
  5. GREEN='\033[0;32m'
  6. BLUE='\033[0;34m'
  7. YELLOW='\033[1;33m'
  8. NC='\033[0m' # No Color
  9. # Configuration
  10. MOUNT_POINT=${MOUNT_POINT:-"/mnt/seaweedfs"}
  11. FILER_ADDR=${FILER_ADDR:-"seaweedfs-filer:8888"}
  12. RDMA_SIDECAR_ADDR=${RDMA_SIDECAR_ADDR:-"rdma-sidecar:8081"}
  13. TEST_RESULTS_DIR=${TEST_RESULTS_DIR:-"/test-results"}
  14. # Test counters
  15. TOTAL_TESTS=0
  16. PASSED_TESTS=0
  17. FAILED_TESTS=0
  18. # Create results directory
  19. mkdir -p "$TEST_RESULTS_DIR"
  20. # Log file
  21. LOG_FILE="$TEST_RESULTS_DIR/integration-test.log"
  22. exec > >(tee -a "$LOG_FILE")
  23. exec 2>&1
  24. echo -e "${BLUE}🧪 SEAWEEDFS RDMA MOUNT INTEGRATION TESTS${NC}"
  25. echo "=========================================="
  26. echo "Mount Point: $MOUNT_POINT"
  27. echo "Filer Address: $FILER_ADDR"
  28. echo "RDMA Sidecar: $RDMA_SIDECAR_ADDR"
  29. echo "Results Directory: $TEST_RESULTS_DIR"
  30. echo "Log File: $LOG_FILE"
  31. echo ""
  32. # Function to run a test
  33. run_test() {
  34. local test_name=$1
  35. local test_command=$2
  36. echo -e "${BLUE}🔬 Running test: $test_name${NC}"
  37. ((TOTAL_TESTS++))
  38. if eval "$test_command"; then
  39. echo -e "${GREEN}✅ PASSED: $test_name${NC}"
  40. ((PASSED_TESTS++))
  41. echo "PASS" > "$TEST_RESULTS_DIR/${test_name}.result"
  42. else
  43. echo -e "${RED}❌ FAILED: $test_name${NC}"
  44. ((FAILED_TESTS++))
  45. echo "FAIL" > "$TEST_RESULTS_DIR/${test_name}.result"
  46. fi
  47. echo ""
  48. }
  49. # Function to wait for mount to be ready
  50. wait_for_mount() {
  51. local max_attempts=30
  52. local attempt=1
  53. echo -e "${BLUE}⏳ Waiting for mount to be ready...${NC}"
  54. while [[ $attempt -le $max_attempts ]]; do
  55. if mountpoint -q "$MOUNT_POINT" 2>/dev/null && ls "$MOUNT_POINT" >/dev/null 2>&1; then
  56. echo -e "${GREEN}✅ Mount is ready${NC}"
  57. return 0
  58. fi
  59. echo " Attempt $attempt/$max_attempts..."
  60. sleep 2
  61. ((attempt++))
  62. done
  63. echo -e "${RED}❌ Mount failed to be ready${NC}"
  64. return 1
  65. }
  66. # Function to check RDMA sidecar
  67. check_rdma_sidecar() {
  68. echo -e "${BLUE}🔍 Checking RDMA sidecar status...${NC}"
  69. local response
  70. if response=$(curl -s "http://$RDMA_SIDECAR_ADDR/health" 2>/dev/null); then
  71. echo "RDMA Sidecar Health: $response"
  72. return 0
  73. else
  74. echo -e "${RED}❌ RDMA sidecar is not responding${NC}"
  75. return 1
  76. fi
  77. }
  78. # Test 1: Mount Point Accessibility
  79. test_mount_accessibility() {
  80. mountpoint -q "$MOUNT_POINT" && ls "$MOUNT_POINT" >/dev/null
  81. }
  82. # Test 2: Basic File Operations
  83. test_basic_file_operations() {
  84. local test_file="$MOUNT_POINT/test_basic_ops.txt"
  85. local test_content="Hello, RDMA World! $(date)"
  86. # Write test
  87. echo "$test_content" > "$test_file" || return 1
  88. # Read test
  89. local read_content
  90. read_content=$(cat "$test_file") || return 1
  91. # Verify content
  92. [[ "$read_content" == "$test_content" ]] || return 1
  93. # Cleanup
  94. rm -f "$test_file"
  95. return 0
  96. }
  97. # Test 3: Large File Operations
  98. test_large_file_operations() {
  99. local test_file="$MOUNT_POINT/test_large_file.dat"
  100. local size_mb=10
  101. # Create large file
  102. dd if=/dev/zero of="$test_file" bs=1M count=$size_mb 2>/dev/null || return 1
  103. # Verify size
  104. local actual_size
  105. actual_size=$(stat -c%s "$test_file" 2>/dev/null) || return 1
  106. local expected_size=$((size_mb * 1024 * 1024))
  107. [[ "$actual_size" -eq "$expected_size" ]] || return 1
  108. # Read test
  109. dd if="$test_file" of=/dev/null bs=1M 2>/dev/null || return 1
  110. # Cleanup
  111. rm -f "$test_file"
  112. return 0
  113. }
  114. # Test 4: Directory Operations
  115. test_directory_operations() {
  116. local test_dir="$MOUNT_POINT/test_directory"
  117. local test_file="$test_dir/test_file.txt"
  118. # Create directory
  119. mkdir -p "$test_dir" || return 1
  120. # Create file in directory
  121. echo "Directory test" > "$test_file" || return 1
  122. # List directory
  123. ls "$test_dir" | grep -q "test_file.txt" || return 1
  124. # Read file
  125. grep -q "Directory test" "$test_file" || return 1
  126. # Cleanup
  127. rm -rf "$test_dir"
  128. return 0
  129. }
  130. # Test 5: Multiple File Operations
  131. test_multiple_files() {
  132. local test_dir="$MOUNT_POINT/test_multiple"
  133. local num_files=20
  134. mkdir -p "$test_dir" || return 1
  135. # Create multiple files
  136. for i in $(seq 1 $num_files); do
  137. echo "File $i content" > "$test_dir/file_$i.txt" || return 1
  138. done
  139. # Verify all files exist and have correct content
  140. for i in $(seq 1 $num_files); do
  141. [[ -f "$test_dir/file_$i.txt" ]] || return 1
  142. grep -q "File $i content" "$test_dir/file_$i.txt" || return 1
  143. done
  144. # List files
  145. local file_count
  146. file_count=$(ls "$test_dir" | wc -l) || return 1
  147. [[ "$file_count" -eq "$num_files" ]] || return 1
  148. # Cleanup
  149. rm -rf "$test_dir"
  150. return 0
  151. }
  152. # Test 6: RDMA Statistics
  153. test_rdma_statistics() {
  154. local stats_response
  155. stats_response=$(curl -s "http://$RDMA_SIDECAR_ADDR/stats" 2>/dev/null) || return 1
  156. # Check if response contains expected fields
  157. echo "$stats_response" | jq -e '.rdma_enabled' >/dev/null || return 1
  158. echo "$stats_response" | jq -e '.total_reads' >/dev/null || return 1
  159. return 0
  160. }
  161. # Test 7: Performance Baseline
  162. test_performance_baseline() {
  163. local test_file="$MOUNT_POINT/performance_test.dat"
  164. local size_mb=50
  165. # Write performance test
  166. local write_start write_end write_time
  167. write_start=$(date +%s%N)
  168. dd if=/dev/zero of="$test_file" bs=1M count=$size_mb 2>/dev/null || return 1
  169. write_end=$(date +%s%N)
  170. write_time=$(((write_end - write_start) / 1000000)) # Convert to milliseconds
  171. # Read performance test
  172. local read_start read_end read_time
  173. read_start=$(date +%s%N)
  174. dd if="$test_file" of=/dev/null bs=1M 2>/dev/null || return 1
  175. read_end=$(date +%s%N)
  176. read_time=$(((read_end - read_start) / 1000000)) # Convert to milliseconds
  177. # Log performance metrics
  178. echo "Performance Metrics:" > "$TEST_RESULTS_DIR/performance.txt"
  179. echo "Write Time: ${write_time}ms for ${size_mb}MB" >> "$TEST_RESULTS_DIR/performance.txt"
  180. echo "Read Time: ${read_time}ms for ${size_mb}MB" >> "$TEST_RESULTS_DIR/performance.txt"
  181. echo "Write Throughput: $(bc <<< "scale=2; $size_mb * 1000 / $write_time") MB/s" >> "$TEST_RESULTS_DIR/performance.txt"
  182. echo "Read Throughput: $(bc <<< "scale=2; $size_mb * 1000 / $read_time") MB/s" >> "$TEST_RESULTS_DIR/performance.txt"
  183. # Cleanup
  184. rm -f "$test_file"
  185. # Performance test always passes (it's just for metrics)
  186. return 0
  187. }
  188. # Main test execution
  189. main() {
  190. echo -e "${BLUE}🚀 Starting integration tests...${NC}"
  191. echo ""
  192. # Wait for mount to be ready
  193. if ! wait_for_mount; then
  194. echo -e "${RED}❌ Mount is not ready, aborting tests${NC}"
  195. exit 1
  196. fi
  197. # Check RDMA sidecar
  198. check_rdma_sidecar || echo -e "${YELLOW}⚠️ RDMA sidecar check failed, continuing with tests${NC}"
  199. echo ""
  200. echo -e "${BLUE}📋 Running test suite...${NC}"
  201. echo ""
  202. # Run all tests
  203. run_test "mount_accessibility" "test_mount_accessibility"
  204. run_test "basic_file_operations" "test_basic_file_operations"
  205. run_test "large_file_operations" "test_large_file_operations"
  206. run_test "directory_operations" "test_directory_operations"
  207. run_test "multiple_files" "test_multiple_files"
  208. run_test "rdma_statistics" "test_rdma_statistics"
  209. run_test "performance_baseline" "test_performance_baseline"
  210. # Generate test summary
  211. echo -e "${BLUE}📊 TEST SUMMARY${NC}"
  212. echo "==============="
  213. echo "Total Tests: $TOTAL_TESTS"
  214. echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}"
  215. echo -e "Failed: ${RED}$FAILED_TESTS${NC}"
  216. if [[ $FAILED_TESTS -eq 0 ]]; then
  217. echo -e "${GREEN}🎉 ALL TESTS PASSED!${NC}"
  218. echo "SUCCESS" > "$TEST_RESULTS_DIR/overall.result"
  219. exit 0
  220. else
  221. echo -e "${RED}💥 SOME TESTS FAILED!${NC}"
  222. echo "FAILURE" > "$TEST_RESULTS_DIR/overall.result"
  223. exit 1
  224. fi
  225. }
  226. # Run main function
  227. main "$@"