Makefile 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. # S3 API Test Makefile
  2. # This Makefile provides comprehensive targets for running S3 versioning tests
  3. .PHONY: help build-weed setup-server start-server stop-server test-versioning test-versioning-quick test-versioning-comprehensive test-all clean logs check-deps
  4. # Configuration
  5. WEED_BINARY := ../../../weed/weed_binary
  6. S3_PORT := 8333
  7. MASTER_PORT := 9333
  8. VOLUME_PORT := 8080
  9. FILER_PORT := 8888
  10. TEST_TIMEOUT := 10m
  11. TEST_PATTERN := TestVersioning
  12. # Default target
  13. help:
  14. @echo "S3 API Test Makefile"
  15. @echo ""
  16. @echo "Available targets:"
  17. @echo " help - Show this help message"
  18. @echo " build-weed - Build the SeaweedFS binary"
  19. @echo " check-deps - Check dependencies and build binary if needed"
  20. @echo " start-server - Start SeaweedFS server for testing"
  21. @echo " start-server-simple - Start server without process cleanup (for CI)"
  22. @echo " stop-server - Stop SeaweedFS server"
  23. @echo " test-versioning - Run all versioning tests"
  24. @echo " test-versioning-quick - Run core versioning tests only"
  25. @echo " test-versioning-simple - Run tests without server management"
  26. @echo " test-versioning-comprehensive - Run comprehensive versioning tests"
  27. @echo " test-all - Run all S3 API tests"
  28. @echo " test-with-server - Start server, run tests, stop server"
  29. @echo " logs - Show server logs"
  30. @echo " clean - Clean up test artifacts and stop server"
  31. @echo " health-check - Check if server is accessible"
  32. @echo ""
  33. @echo "Configuration:"
  34. @echo " S3_PORT=${S3_PORT}"
  35. @echo " TEST_TIMEOUT=${TEST_TIMEOUT}"
  36. # Check dependencies
  37. # Build the SeaweedFS binary
  38. build-weed:
  39. @echo "Building SeaweedFS binary..."
  40. @cd ../../../weed && go build -o weed_binary .
  41. @chmod +x $(WEED_BINARY)
  42. @echo "✅ SeaweedFS binary built at $(WEED_BINARY)"
  43. check-deps: build-weed
  44. @echo "Checking dependencies..."
  45. @echo "🔍 DEBUG: Checking Go installation..."
  46. @command -v go >/dev/null 2>&1 || (echo "Go is required but not installed" && exit 1)
  47. @echo "🔍 DEBUG: Go version: $$(go version)"
  48. @echo "🔍 DEBUG: Checking binary at $(WEED_BINARY)..."
  49. @test -f $(WEED_BINARY) || (echo "SeaweedFS binary not found at $(WEED_BINARY)" && exit 1)
  50. @echo "🔍 DEBUG: Binary size: $$(ls -lh $(WEED_BINARY) | awk '{print $$5}')"
  51. @echo "🔍 DEBUG: Binary permissions: $$(ls -la $(WEED_BINARY) | awk '{print $$1}')"
  52. @echo "🔍 DEBUG: Checking Go module dependencies..."
  53. @go list -m github.com/aws/aws-sdk-go-v2 >/dev/null 2>&1 || (echo "AWS SDK Go v2 not found. Run 'go mod tidy'." && exit 1)
  54. @go list -m github.com/stretchr/testify >/dev/null 2>&1 || (echo "Testify not found. Run 'go mod tidy'." && exit 1)
  55. @echo "✅ All dependencies are available"
  56. # Start SeaweedFS server for testing
  57. start-server: check-deps
  58. @echo "Starting SeaweedFS server..."
  59. @echo "🔍 DEBUG: Current working directory: $$(pwd)"
  60. @echo "🔍 DEBUG: Checking for existing weed processes..."
  61. @ps aux | grep weed | grep -v grep || echo "No existing weed processes found"
  62. @echo "🔍 DEBUG: Cleaning up any existing PID file..."
  63. @rm -f weed-server.pid
  64. @echo "🔍 DEBUG: Checking for port conflicts..."
  65. @if netstat -tlnp 2>/dev/null | grep $(S3_PORT) >/dev/null; then \
  66. echo "⚠️ Port $(S3_PORT) is already in use, trying to find the process..."; \
  67. netstat -tlnp 2>/dev/null | grep $(S3_PORT) || true; \
  68. else \
  69. echo "✅ Port $(S3_PORT) is available"; \
  70. fi
  71. @echo "🔍 DEBUG: Checking binary at $(WEED_BINARY)"
  72. @ls -la $(WEED_BINARY) || (echo "❌ Binary not found!" && exit 1)
  73. @echo "🔍 DEBUG: Checking config file at ../../../docker/compose/s3.json"
  74. @ls -la ../../../docker/compose/s3.json || echo "⚠️ Config file not found, continuing without it"
  75. @echo "🔍 DEBUG: Creating volume directory..."
  76. @mkdir -p ./test-volume-data
  77. @echo "🔍 DEBUG: Launching SeaweedFS server in background..."
  78. @echo "🔍 DEBUG: Command: $(WEED_BINARY) server -debug -s3 -s3.port=$(S3_PORT) -s3.allowEmptyFolder=false -s3.allowDeleteBucketNotEmpty=true -s3.config=../../../docker/compose/s3.json -filer -filer.maxMB=64 -master.volumeSizeLimitMB=50 -volume.max=100 -dir=./test-volume-data -volume.preStopSeconds=1 -metricsPort=9324"
  79. @$(WEED_BINARY) server \
  80. -debug \
  81. -s3 \
  82. -s3.port=$(S3_PORT) \
  83. -s3.allowEmptyFolder=false \
  84. -s3.allowDeleteBucketNotEmpty=true \
  85. -s3.config=../../../docker/compose/s3.json \
  86. -filer \
  87. -filer.maxMB=64 \
  88. -master.volumeSizeLimitMB=50 \
  89. -volume.max=100 \
  90. -dir=./test-volume-data \
  91. -volume.preStopSeconds=1 \
  92. -metricsPort=9324 \
  93. > weed-test.log 2>&1 & echo $$! > weed-server.pid
  94. @echo "🔍 DEBUG: Server PID: $$(cat weed-server.pid 2>/dev/null || echo 'PID file not found')"
  95. @echo "🔍 DEBUG: Checking if PID is still running..."
  96. @sleep 2
  97. @if [ -f weed-server.pid ]; then \
  98. SERVER_PID=$$(cat weed-server.pid); \
  99. ps -p $$SERVER_PID || echo "⚠️ Server PID $$SERVER_PID not found after 2 seconds"; \
  100. else \
  101. echo "⚠️ PID file not found"; \
  102. fi
  103. @echo "🔍 DEBUG: Waiting for server to start (up to 90 seconds)..."
  104. @for i in $$(seq 1 90); do \
  105. echo "🔍 DEBUG: Attempt $$i/90 - checking port $(S3_PORT)"; \
  106. if curl -s http://localhost:$(S3_PORT) >/dev/null 2>&1; then \
  107. echo "✅ SeaweedFS server started successfully on port $(S3_PORT) after $$i seconds"; \
  108. exit 0; \
  109. fi; \
  110. if [ $$i -eq 5 ]; then \
  111. echo "🔍 DEBUG: After 5 seconds, checking process and logs..."; \
  112. ps aux | grep weed | grep -v grep || echo "No weed processes found"; \
  113. if [ -f weed-test.log ]; then \
  114. echo "=== First server logs ==="; \
  115. head -20 weed-test.log; \
  116. fi; \
  117. fi; \
  118. if [ $$i -eq 15 ]; then \
  119. echo "🔍 DEBUG: After 15 seconds, checking port bindings..."; \
  120. netstat -tlnp 2>/dev/null | grep $(S3_PORT) || echo "Port $(S3_PORT) not bound"; \
  121. netstat -tlnp 2>/dev/null | grep 9333 || echo "Port 9333 not bound"; \
  122. netstat -tlnp 2>/dev/null | grep 8080 || echo "Port 8080 not bound"; \
  123. fi; \
  124. if [ $$i -eq 30 ]; then \
  125. echo "⚠️ Server taking longer than expected (30s), checking logs..."; \
  126. if [ -f weed-test.log ]; then \
  127. echo "=== Recent server logs ==="; \
  128. tail -20 weed-test.log; \
  129. fi; \
  130. fi; \
  131. sleep 1; \
  132. done; \
  133. echo "❌ Server failed to start within 90 seconds"; \
  134. echo "🔍 DEBUG: Final process check:"; \
  135. ps aux | grep weed | grep -v grep || echo "No weed processes found"; \
  136. echo "🔍 DEBUG: Final port check:"; \
  137. netstat -tlnp 2>/dev/null | grep -E "(8333|9333|8080)" || echo "No ports bound"; \
  138. echo "=== Full server logs ==="; \
  139. if [ -f weed-test.log ]; then \
  140. cat weed-test.log; \
  141. else \
  142. echo "No log file found"; \
  143. fi; \
  144. exit 1
  145. # Stop SeaweedFS server
  146. stop-server:
  147. @echo "Stopping SeaweedFS server..."
  148. @if [ -f weed-server.pid ]; then \
  149. SERVER_PID=$$(cat weed-server.pid); \
  150. echo "Killing server PID $$SERVER_PID"; \
  151. if ps -p $$SERVER_PID >/dev/null 2>&1; then \
  152. kill -TERM $$SERVER_PID 2>/dev/null || true; \
  153. sleep 2; \
  154. if ps -p $$SERVER_PID >/dev/null 2>&1; then \
  155. echo "Process still running, sending KILL signal..."; \
  156. kill -KILL $$SERVER_PID 2>/dev/null || true; \
  157. sleep 1; \
  158. fi; \
  159. else \
  160. echo "Process $$SERVER_PID not found (already stopped)"; \
  161. fi; \
  162. rm -f weed-server.pid; \
  163. else \
  164. echo "No PID file found, checking for running processes..."; \
  165. echo "⚠️ Skipping automatic process cleanup to avoid CI issues"; \
  166. echo "Note: Any remaining weed processes should be cleaned up by the CI environment"; \
  167. fi
  168. @echo "✅ SeaweedFS server stopped"
  169. # Show server logs
  170. logs:
  171. @if test -f weed-test.log; then \
  172. echo "=== SeaweedFS Server Logs ==="; \
  173. tail -f weed-test.log; \
  174. else \
  175. echo "No log file found. Server may not be running."; \
  176. fi
  177. # Core versioning tests (equivalent to Python s3tests)
  178. test-versioning-quick: check-deps
  179. @echo "Running core S3 versioning tests..."
  180. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestBucketListReturnDataVersioning|TestVersioningBasicWorkflow|TestVersioningDeleteMarkers" .
  181. @echo "✅ Core versioning tests completed"
  182. # All versioning tests
  183. test-versioning: check-deps
  184. @echo "Running all S3 versioning tests..."
  185. @go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" .
  186. @echo "✅ All versioning tests completed"
  187. # Comprehensive versioning tests (including edge cases)
  188. test-versioning-comprehensive: check-deps
  189. @echo "Running comprehensive S3 versioning tests..."
  190. @go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" . -count=1
  191. @echo "✅ Comprehensive versioning tests completed"
  192. # All S3 API tests
  193. test-all: check-deps
  194. @echo "Running all S3 API tests..."
  195. @go test -v -timeout=$(TEST_TIMEOUT) ./...
  196. @echo "✅ All S3 API tests completed"
  197. # Run tests with automatic server management
  198. test-with-server: start-server
  199. @echo "🔍 DEBUG: Server started successfully, now running versioning tests..."
  200. @echo "🔍 DEBUG: Test pattern: $(TEST_PATTERN)"
  201. @echo "🔍 DEBUG: Test timeout: $(TEST_TIMEOUT)"
  202. @echo "Running versioning tests with managed server..."
  203. @trap "$(MAKE) stop-server" EXIT; \
  204. $(MAKE) test-versioning || (echo "❌ Tests failed, showing server logs:" && echo "=== Last 50 lines of server logs ===" && tail -50 weed-test.log && echo "=== End of server logs ===" && exit 1)
  205. @$(MAKE) stop-server
  206. @echo "✅ Tests completed and server stopped"
  207. # Test with different configurations
  208. test-versioning-with-configs: check-deps
  209. @echo "Testing with different S3 configurations..."
  210. @echo "Testing with empty folder allowed..."
  211. @$(WEED_BINARY) server -s3 -s3.port=$(S3_PORT) -s3.allowEmptyFolder=true -filer -master.volumeSizeLimitMB=100 -volume.max=100 > weed-test-config1.log 2>&1 & echo $$! > weed-config1.pid
  212. @sleep 5
  213. @go test -v -timeout=5m -run "TestVersioningBasicWorkflow" . || true
  214. @if [ -f weed-config1.pid ]; then kill -TERM $$(cat weed-config1.pid) 2>/dev/null || true; rm -f weed-config1.pid; fi
  215. @sleep 2
  216. @echo "Testing with delete bucket not empty disabled..."
  217. @$(WEED_BINARY) server -s3 -s3.port=$(S3_PORT) -s3.allowDeleteBucketNotEmpty=false -filer -master.volumeSizeLimitMB=100 -volume.max=100 > weed-test-config2.log 2>&1 & echo $$! > weed-config2.pid
  218. @sleep 5
  219. @go test -v -timeout=5m -run "TestVersioningBasicWorkflow" . || true
  220. @if [ -f weed-config2.pid ]; then kill -TERM $$(cat weed-config2.pid) 2>/dev/null || true; rm -f weed-config2.pid; fi
  221. @echo "✅ Configuration tests completed"
  222. # Performance/stress testing
  223. test-versioning-stress: check-deps
  224. @echo "Running stress tests for versioning..."
  225. @go test -v -timeout=20m -run "TestVersioningConcurrentOperations" . -count=5
  226. @echo "✅ Stress tests completed"
  227. # Generate test reports
  228. test-report: check-deps
  229. @echo "Generating test reports..."
  230. @mkdir -p reports
  231. @go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" . -json > reports/test-results.json 2>&1 || true
  232. @go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" . -coverprofile=reports/coverage.out 2>&1 || true
  233. @go tool cover -html=reports/coverage.out -o reports/coverage.html 2>/dev/null || true
  234. @echo "✅ Test reports generated in reports/ directory"
  235. # Clean up test artifacts
  236. clean:
  237. @echo "Cleaning up test artifacts..."
  238. @$(MAKE) stop-server
  239. @rm -f weed-test*.log weed-server.pid weed-config*.pid
  240. @rm -rf reports/
  241. @rm -rf test-volume-data/
  242. @go clean -testcache
  243. @echo "✅ Cleanup completed"
  244. # Debug mode - start server with verbose logging
  245. debug-server:
  246. @echo "Starting SeaweedFS server in debug mode..."
  247. @$(MAKE) stop-server
  248. @mkdir -p ./test-volume-data
  249. @$(WEED_BINARY) server \
  250. -debug \
  251. -s3 \
  252. -s3.port=$(S3_PORT) \
  253. -s3.allowEmptyFolder=false \
  254. -s3.allowDeleteBucketNotEmpty=true \
  255. -s3.config=../../../docker/compose/s3.json \
  256. -filer \
  257. -filer.maxMB=16 \
  258. -master.volumeSizeLimitMB=50 \
  259. -volume.max=100 \
  260. -dir=./test-volume-data \
  261. -volume.preStopSeconds=1 \
  262. -metricsPort=9324
  263. # Run a single test for debugging
  264. debug-test: check-deps
  265. @echo "Running single test for debugging..."
  266. @go test -v -timeout=5m -run "TestBucketListReturnDataVersioning" . -count=1
  267. # Continuous testing (re-run tests on file changes)
  268. watch-tests:
  269. @echo "Starting continuous testing (requires 'entr' command)..."
  270. @command -v entr >/dev/null 2>&1 || (echo "Install 'entr' for file watching: brew install entr (macOS) or apt-get install entr (Linux)" && exit 1)
  271. @find . -name "*.go" | entr -c $(MAKE) test-versioning-quick
  272. # Install missing Go dependencies
  273. install-deps:
  274. @echo "Installing Go dependencies..."
  275. @go mod download
  276. @go mod tidy
  277. @echo "✅ Dependencies installed"
  278. # Validate test configuration
  279. validate-config:
  280. @echo "Validating test configuration..."
  281. @test -f test_config.json || (echo "❌ test_config.json not found" && exit 1)
  282. @python3 -m json.tool test_config.json > /dev/null 2>&1 || (echo "❌ test_config.json is not valid JSON" && exit 1)
  283. @echo "✅ Configuration is valid"
  284. # Quick health check
  285. health-check:
  286. @echo "Running health check..."
  287. @curl -s http://localhost:$(S3_PORT) >/dev/null 2>&1 && echo "✅ S3 API is accessible" || echo "❌ S3 API is not accessible"
  288. @curl -s http://localhost:9324/metrics >/dev/null 2>&1 && echo "✅ Metrics endpoint is accessible" || echo "❌ Metrics endpoint is not accessible"
  289. # Simple server start without process cleanup (for CI troubleshooting)
  290. start-server-simple: check-deps
  291. @echo "Starting SeaweedFS server (simple mode)..."
  292. @$(WEED_BINARY) server \
  293. -debug \
  294. -s3 \
  295. -s3.port=$(S3_PORT) \
  296. -s3.allowEmptyFolder=false \
  297. -s3.allowDeleteBucketNotEmpty=true \
  298. -s3.config=../../../docker/compose/s3.json \
  299. -filer \
  300. -filer.maxMB=64 \
  301. -master.volumeSizeLimitMB=50 \
  302. -volume.max=100 \
  303. -volume.preStopSeconds=1 \
  304. -metricsPort=9324 \
  305. > weed-test.log 2>&1 & echo $$! > weed-server.pid
  306. @echo "Server PID: $$(cat weed-server.pid)"
  307. @echo "Waiting for server to start..."
  308. @sleep 10
  309. @curl -s http://localhost:$(S3_PORT) >/dev/null 2>&1 && echo "✅ Server started successfully" || echo "❌ Server failed to start"
  310. # Simple test run without server management
  311. test-versioning-simple: check-deps
  312. @echo "Running versioning tests (assuming server is already running)..."
  313. @go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" .
  314. @echo "✅ Tests completed"
  315. # Force cleanup all weed processes (use with caution)
  316. force-cleanup:
  317. @echo "⚠️ Force cleaning up all weed processes..."
  318. @echo "This will attempt to kill ALL weed processes on the system"
  319. @ps aux | grep weed | grep -v grep || echo "No weed processes found"
  320. @killall -TERM weed_binary 2>/dev/null || echo "No weed_binary processes to terminate"
  321. @sleep 2
  322. @killall -KILL weed_binary 2>/dev/null || echo "No weed_binary processes to kill"
  323. @rm -f weed-server.pid weed-config*.pid
  324. @echo "✅ Force cleanup completed"
  325. # Compare with Python s3tests (if available)
  326. compare-python-tests:
  327. @echo "Comparing Go tests with Python s3tests..."
  328. @echo "Go test: TestBucketListReturnDataVersioning"
  329. @echo "Python equivalent: test_bucket_list_return_data_versioning"
  330. @echo ""
  331. @echo "Running Go version..."
  332. @time go test -v -run "TestBucketListReturnDataVersioning" . 2>&1 | grep -E "(PASS|FAIL|took)"