Makefile 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. # Makefile for S3 Copying Tests
  2. # This Makefile provides targets for running comprehensive S3 copying tests
  3. # Default values
  4. SEAWEEDFS_BINARY ?= weed
  5. S3_PORT ?= 8333
  6. FILER_PORT ?= 8888
  7. VOLUME_PORT ?= 8080
  8. MASTER_PORT ?= 9333
  9. TEST_TIMEOUT ?= 10m
  10. BUCKET_PREFIX ?= test-copying-
  11. ACCESS_KEY ?= some_access_key1
  12. SECRET_KEY ?= some_secret_key1
  13. VOLUME_MAX_SIZE_MB ?= 50
  14. # Test directory
  15. TEST_DIR := $(shell pwd)
  16. SEAWEEDFS_ROOT := $(shell cd ../../../ && pwd)
  17. # Colors for output
  18. RED := \033[0;31m
  19. GREEN := \033[0;32m
  20. YELLOW := \033[1;33m
  21. NC := \033[0m # No Color
  22. .PHONY: all test clean start-seaweedfs stop-seaweedfs check-binary help
  23. all: test-basic
  24. help:
  25. @echo "SeaweedFS S3 Copying Tests"
  26. @echo ""
  27. @echo "Available targets:"
  28. @echo " test-basic - Run basic S3 put/get tests first"
  29. @echo " test - Run all S3 copying tests"
  30. @echo " test-quick - Run quick tests only"
  31. @echo " test-full - Run full test suite including large files"
  32. @echo " start-seaweedfs - Start SeaweedFS server for testing"
  33. @echo " stop-seaweedfs - Stop SeaweedFS server"
  34. @echo " clean - Clean up test artifacts"
  35. @echo " check-binary - Check if SeaweedFS binary exists"
  36. @echo ""
  37. @echo "Configuration:"
  38. @echo " SEAWEEDFS_BINARY=$(SEAWEEDFS_BINARY)"
  39. @echo " S3_PORT=$(S3_PORT)"
  40. @echo " FILER_PORT=$(FILER_PORT)"
  41. @echo " VOLUME_PORT=$(VOLUME_PORT)"
  42. @echo " MASTER_PORT=$(MASTER_PORT)"
  43. @echo " TEST_TIMEOUT=$(TEST_TIMEOUT)"
  44. @echo " VOLUME_MAX_SIZE_MB=$(VOLUME_MAX_SIZE_MB)"
  45. check-binary:
  46. @if ! command -v $(SEAWEEDFS_BINARY) > /dev/null 2>&1; then \
  47. echo "$(RED)Error: SeaweedFS binary '$(SEAWEEDFS_BINARY)' not found in PATH$(NC)"; \
  48. echo "Please build SeaweedFS first by running 'make' in the root directory"; \
  49. exit 1; \
  50. fi
  51. @echo "$(GREEN)SeaweedFS binary found: $$(which $(SEAWEEDFS_BINARY))$(NC)"
  52. start-seaweedfs: check-binary
  53. @echo "$(YELLOW)Starting SeaweedFS server...$(NC)"
  54. @pkill -f "weed master" || true
  55. @pkill -f "weed volume" || true
  56. @pkill -f "weed filer" || true
  57. @pkill -f "weed s3" || true
  58. @sleep 2
  59. # Create necessary directories
  60. @mkdir -p /tmp/seaweedfs-test-copying-master
  61. @mkdir -p /tmp/seaweedfs-test-copying-volume
  62. # Start master server with volume size limit
  63. @nohup $(SEAWEEDFS_BINARY) master -port=$(MASTER_PORT) -mdir=/tmp/seaweedfs-test-copying-master -volumeSizeLimitMB=$(VOLUME_MAX_SIZE_MB) -ip=127.0.0.1 > /tmp/seaweedfs-master.log 2>&1 &
  64. @sleep 3
  65. # Start volume server
  66. @nohup $(SEAWEEDFS_BINARY) volume -port=$(VOLUME_PORT) -mserver=127.0.0.1:$(MASTER_PORT) -dir=/tmp/seaweedfs-test-copying-volume -ip=127.0.0.1 > /tmp/seaweedfs-volume.log 2>&1 &
  67. @sleep 3
  68. # Start filer server (using standard SeaweedFS gRPC port convention: HTTP port + 10000)
  69. @nohup $(SEAWEEDFS_BINARY) filer -port=$(FILER_PORT) -port.grpc=$$(( $(FILER_PORT) + 10000 )) -master=127.0.0.1:$(MASTER_PORT) -ip=127.0.0.1 > /tmp/seaweedfs-filer.log 2>&1 &
  70. @sleep 3
  71. # Create S3 configuration
  72. @echo '{"identities":[{"name":"$(ACCESS_KEY)","credentials":[{"accessKey":"$(ACCESS_KEY)","secretKey":"$(SECRET_KEY)"}],"actions":["Admin","Read","Write"]}]}' > /tmp/seaweedfs-s3.json
  73. # Start S3 server
  74. @nohup $(SEAWEEDFS_BINARY) s3 -port=$(S3_PORT) -filer=127.0.0.1:$(FILER_PORT) -config=/tmp/seaweedfs-s3.json -ip.bind=127.0.0.1 > /tmp/seaweedfs-s3.log 2>&1 &
  75. @sleep 5
  76. # Wait for S3 service to be ready
  77. @echo "$(YELLOW)Waiting for S3 service to be ready...$(NC)"
  78. @for i in $$(seq 1 30); do \
  79. if curl -s -f http://127.0.0.1:$(S3_PORT) > /dev/null 2>&1; then \
  80. echo "$(GREEN)S3 service is ready$(NC)"; \
  81. break; \
  82. fi; \
  83. echo "Waiting for S3 service... ($$i/30)"; \
  84. sleep 1; \
  85. done
  86. # Additional wait for filer gRPC to be ready
  87. @echo "$(YELLOW)Waiting for filer gRPC to be ready...$(NC)"
  88. @sleep 2
  89. @echo "$(GREEN)SeaweedFS server started successfully$(NC)"
  90. @echo "Master: http://localhost:$(MASTER_PORT)"
  91. @echo "Volume: http://localhost:$(VOLUME_PORT)"
  92. @echo "Filer: http://localhost:$(FILER_PORT)"
  93. @echo "S3: http://localhost:$(S3_PORT)"
  94. @echo "Volume Max Size: $(VOLUME_MAX_SIZE_MB)MB"
  95. stop-seaweedfs:
  96. @echo "$(YELLOW)Stopping SeaweedFS server...$(NC)"
  97. @pkill -f "weed master" || true
  98. @pkill -f "weed volume" || true
  99. @pkill -f "weed filer" || true
  100. @pkill -f "weed s3" || true
  101. @sleep 2
  102. @echo "$(GREEN)SeaweedFS server stopped$(NC)"
  103. clean:
  104. @echo "$(YELLOW)Cleaning up test artifacts...$(NC)"
  105. @rm -rf /tmp/seaweedfs-test-copying-*
  106. @rm -f /tmp/seaweedfs-*.log
  107. @rm -f /tmp/seaweedfs-s3.json
  108. @echo "$(GREEN)Cleanup completed$(NC)"
  109. test-basic: check-binary
  110. @echo "$(YELLOW)Running basic S3 put/get tests...$(NC)"
  111. @$(MAKE) start-seaweedfs
  112. @sleep 5
  113. @echo "$(GREEN)Starting basic tests...$(NC)"
  114. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestBasic" ./test/s3/copying || (echo "$(RED)Basic tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  115. @$(MAKE) stop-seaweedfs
  116. @echo "$(GREEN)Basic tests completed successfully!$(NC)"
  117. test: test-basic
  118. @echo "$(YELLOW)Running S3 copying tests...$(NC)"
  119. @$(MAKE) start-seaweedfs
  120. @sleep 5
  121. @echo "$(GREEN)Starting tests...$(NC)"
  122. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "Test.*" ./test/s3/copying || (echo "$(RED)Tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  123. @$(MAKE) stop-seaweedfs
  124. @echo "$(GREEN)All tests completed successfully!$(NC)"
  125. test-quick: check-binary
  126. @echo "$(YELLOW)Running quick S3 copying tests...$(NC)"
  127. @$(MAKE) start-seaweedfs
  128. @sleep 5
  129. @echo "$(GREEN)Starting quick tests...$(NC)"
  130. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestObjectCopy|TestCopyObjectIf" ./test/s3/copying || (echo "$(RED)Tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  131. @$(MAKE) stop-seaweedfs
  132. @echo "$(GREEN)Quick tests completed successfully!$(NC)"
  133. test-full: check-binary
  134. @echo "$(YELLOW)Running full S3 copying test suite...$(NC)"
  135. @$(MAKE) start-seaweedfs
  136. @sleep 5
  137. @echo "$(GREEN)Starting full test suite...$(NC)"
  138. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=30m -run "Test.*" ./test/s3/copying || (echo "$(RED)Tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  139. @$(MAKE) stop-seaweedfs
  140. @echo "$(GREEN)Full test suite completed successfully!$(NC)"
  141. test-multipart: check-binary
  142. @echo "$(YELLOW)Running multipart copying tests...$(NC)"
  143. @$(MAKE) start-seaweedfs
  144. @sleep 5
  145. @echo "$(GREEN)Starting multipart tests...$(NC)"
  146. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestMultipart" ./test/s3/copying || (echo "$(RED)Tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  147. @$(MAKE) stop-seaweedfs
  148. @echo "$(GREEN)Multipart tests completed successfully!$(NC)"
  149. test-conditional: check-binary
  150. @echo "$(YELLOW)Running conditional copying tests...$(NC)"
  151. @$(MAKE) start-seaweedfs
  152. @sleep 5
  153. @echo "$(GREEN)Starting conditional tests...$(NC)"
  154. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestCopyObjectIf" ./test/s3/copying || (echo "$(RED)Tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  155. @$(MAKE) stop-seaweedfs
  156. @echo "$(GREEN)Conditional tests completed successfully!$(NC)"
  157. # Debug targets
  158. debug-logs:
  159. @echo "$(YELLOW)=== Master Log ===$(NC)"
  160. @tail -n 50 /tmp/seaweedfs-master.log || echo "No master log found"
  161. @echo "$(YELLOW)=== Volume Log ===$(NC)"
  162. @tail -n 50 /tmp/seaweedfs-volume.log || echo "No volume log found"
  163. @echo "$(YELLOW)=== Filer Log ===$(NC)"
  164. @tail -n 50 /tmp/seaweedfs-filer.log || echo "No filer log found"
  165. @echo "$(YELLOW)=== S3 Log ===$(NC)"
  166. @tail -n 50 /tmp/seaweedfs-s3.log || echo "No S3 log found"
  167. debug-status:
  168. @echo "$(YELLOW)=== Process Status ===$(NC)"
  169. @ps aux | grep -E "(weed|seaweedfs)" | grep -v grep || echo "No SeaweedFS processes found"
  170. @echo "$(YELLOW)=== Port Status ===$(NC)"
  171. @netstat -an | grep -E "($(MASTER_PORT)|$(VOLUME_PORT)|$(FILER_PORT)|$(S3_PORT))" || echo "No ports in use"
  172. # Manual test targets for development
  173. manual-start: start-seaweedfs
  174. @echo "$(GREEN)SeaweedFS is now running for manual testing$(NC)"
  175. @echo "Run 'make manual-stop' when finished"
  176. manual-stop: stop-seaweedfs clean
  177. # CI/CD targets
  178. ci-test: test-quick
  179. # Benchmark targets
  180. benchmark: check-binary
  181. @echo "$(YELLOW)Running S3 copying benchmarks...$(NC)"
  182. @$(MAKE) start-seaweedfs
  183. @sleep 5
  184. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=30m -bench=. -run=Benchmark ./test/s3/copying || (echo "$(RED)Benchmarks failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  185. @$(MAKE) stop-seaweedfs
  186. @echo "$(GREEN)Benchmarks completed!$(NC)"
  187. # Stress test
  188. stress: check-binary
  189. @echo "$(YELLOW)Running S3 copying stress tests...$(NC)"
  190. @$(MAKE) start-seaweedfs
  191. @sleep 5
  192. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=60m -run="TestMultipartCopyMultipleSizes" -count=10 ./test/s3/copying || (echo "$(RED)Stress tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  193. @$(MAKE) stop-seaweedfs
  194. @echo "$(GREEN)Stress tests completed!$(NC)"
  195. # Performance test with larger files
  196. perf: check-binary
  197. @echo "$(YELLOW)Running S3 copying performance tests...$(NC)"
  198. @$(MAKE) start-seaweedfs
  199. @sleep 5
  200. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=60m -run="TestMultipartCopyMultipleSizes" ./test/s3/copying || (echo "$(RED)Performance tests failed$(NC)" && $(MAKE) stop-seaweedfs && exit 1)
  201. @$(MAKE) stop-seaweedfs
  202. @echo "$(GREEN)Performance tests completed!$(NC)"