This directory contains comprehensive tests for the Pickbox distributed file storage system.
- Manager Tests: Test storage manager creation, node management, and Raft integration
- Node Tests: Test individual node operations (store/retrieve chunks, concurrency)
- Vector Clock Tests: Test distributed conflict resolution mechanisms
- Raft Manager Tests: Test Raft consensus and FSM operations
- FSM Tests: Test file system state machine operations
- Command Tests: Test command serialization/deserialization
- Hash Function Tests: Test content deduplication mechanisms
- File State Tests: Test file tracking and metadata management
End-to-end tests that spin up actual 3-node clusters:
- Basic Replication: File creation and replication across all nodes
- File Modification: Updates propagating between nodes
- File Deletion: Deletion events replicating to all nodes
- Concurrent Writes: Multiple nodes writing simultaneously
- Nested Directories: Deep directory structure replication
- Large Files: 1MB+ file replication performance
- Node Failure Recovery: Fault tolerance and recovery testing
Performance testing for critical operations:
- Hash function performance
- File state management
- Vector clock operations
- FSM Apply operations
- JSON marshaling/unmarshaling
# Run all tests
./scripts/run_tests.sh
# Run with stress tests
./scripts/run_tests.sh --stress# Unit tests only
go test -v ./pkg/storage
go test -v ./cmd/multi_replication
# Integration tests only
cd test && go test -v .
# Benchmarks only
go test -bench=. ./pkg/storage
go test -bench=. ./cmd/multi_replication# Generate coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# View coverage in terminal
go tool cover -func=coverage.out- Raft Ports: 8000-8002
- Admin Ports: 9001-9003
- Test Directories:
/tmp/pickbox-integration-test/node{1,2,3}
- Replication Timeout: 30 seconds
- Integration Test Timeout: 240 seconds (4 minutes)
- Node Startup Time: 2-3 seconds per node
- Unit Tests: 95%+ code coverage
- Integration Tests: Full end-to-end workflows
- Concurrent Testing: Race condition detection
- Error Handling: Failure scenario testing
- Performance: Benchmark and stress testing
- Mock Raft snapshot sinks
- Isolated test directories
- Process cleanup between tests
- Port conflict prevention
- Network partitions (node failure/recovery)
- Concurrent multi-user editing
- Large file handling (1MB+)
- Deep directory structures
- Content deduplication
-
Port Conflicts
# Check for running processes lsof -i :8000-8002 lsof -i :9001-9003 # Kill hanging processes pkill -f multi_replication
-
Test Directory Cleanup
# Manual cleanup rm -rf /tmp/pickbox-test-* /tmp/test-*
-
Build Issues
# Rebuild binary cd cmd/multi_replication go build -o ../../bin/multi_replication .
# Enable detailed test output
go test -v -race ./...
# Test specific function
go test -run TestBasicReplication -v ./test# Set custom timeouts
export PICKBOX_TEST_TIMEOUT=60s
export PICKBOX_REPLICATION_DELAY=10s
# Enable debug logging
export PICKBOX_DEBUG=true- Hash Function: ~1M hashes/second
- File State Update: ~100K updates/second
- Replication Latency: 1-4 seconds
- Large File (1MB): <60 seconds full replication
# Storage benchmarks
cd pkg/storage && go test -bench=. -benchmem
# Multi-replication benchmarks
cd cmd/multi_replication && go test -bench=. -benchmem
# Custom benchmark runs
go test -bench=BenchmarkHashContent -count=5 -benchtime=10sThe test suite is designed for CI/CD environments:
# Example GitHub Actions
- name: Run Tests
run: |
./scripts/run_tests.sh
- name: Upload Coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage.out# Test in containerized environment
FROM golang:1.21
COPY . /app
WORKDIR /app
RUN ./scripts/run_tests.shWhen adding new tests:
- Unit Tests: Add to appropriate
*_test.gofiles - Integration Tests: Add to
test/integration_test.go - Benchmarks: Add
Benchmark*functions - Update Documentation: Update this README
TestFunctionName_Scenariofor unit testsTestEndToEndScenariofor integration testsBenchmarkOperationfor performance tests
- Use table-driven tests for multiple scenarios
- Include both positive and negative test cases
- Test concurrent operations with goroutines
- Mock external dependencies appropriately
- Clean up resources in test teardown