Skip to content

Commit 6b67228

Browse files
authored
test(docker): add multi-validator test infrastructure and fix healthchecks (#7)
* fix(docker): use test -e for healthcheck to handle directory storage * test(docker): add multi-validator test infrastructure Add comprehensive test suite and Docker configuration for testing multi-validator P2P networks locally: - docker-compose.multi-validator.yml for 4-validator test network - Dockerfile.test-validator for lightweight test builds - test-comprehensive.sh for running full test suite - entrypoint-test.sh for configuring test validators
1 parent d7a46e3 commit 6b67228

6 files changed

Lines changed: 490 additions & 2 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ EXPOSE 9000
9191

9292
# Health check
9393
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
94-
CMD test -f /data/distributed.db || exit 1
94+
CMD test -e /data/distributed.db || exit 1
9595

9696
# Default entrypoint
9797
ENTRYPOINT ["validator-node"]

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ services:
5050
command: ["validator-node", "--data-dir", "/data", "--listen-addr", "/ip4/0.0.0.0/tcp/9000"]
5151

5252
healthcheck:
53-
test: ["CMD-SHELL", "test -f /data/distributed.db || exit 1"]
53+
test: ["CMD-SHELL", "test -e /data/distributed.db || exit 1"]
5454
interval: 30s
5555
timeout: 10s
5656
retries: 3

scripts/test-comprehensive.sh

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
#!/bin/bash
2+
# =============================================================================
3+
# Platform Comprehensive Test Suite
4+
# =============================================================================
5+
# Runs all tests including unit tests, integration tests, Docker tests,
6+
# and multi-validator P2P network tests.
7+
#
8+
# Usage:
9+
# ./scripts/test-comprehensive.sh
10+
#
11+
# Requirements:
12+
# - Docker daemon running
13+
# - Rust toolchain installed
14+
# - Network access for Bittensor integration tests
15+
# =============================================================================
16+
17+
set -e
18+
19+
# Colors for output
20+
RED='\033[0;31m'
21+
GREEN='\033[0;32m'
22+
YELLOW='\033[1;33m'
23+
BLUE='\033[0;34m'
24+
NC='\033[0m' # No Color
25+
26+
# Test result counters
27+
PASSED=0
28+
FAILED=0
29+
SKIPPED=0
30+
31+
# Log functions
32+
log_info() {
33+
echo -e "${BLUE}[INFO]${NC} $1"
34+
}
35+
36+
log_success() {
37+
echo -e "${GREEN}[PASS]${NC} $1"
38+
((PASSED++))
39+
}
40+
41+
log_failure() {
42+
echo -e "${RED}[FAIL]${NC} $1"
43+
((FAILED++))
44+
}
45+
46+
log_warning() {
47+
echo -e "${YELLOW}[WARN]${NC} $1"
48+
}
49+
50+
log_skip() {
51+
echo -e "${YELLOW}[SKIP]${NC} $1"
52+
((SKIPPED++))
53+
}
54+
55+
# Header
56+
echo "============================================================================="
57+
echo " Platform Comprehensive Test Suite"
58+
echo "============================================================================="
59+
echo ""
60+
date
61+
echo ""
62+
63+
# =============================================================================
64+
# Phase 1: Build
65+
# =============================================================================
66+
echo ""
67+
echo "============================================================================="
68+
echo "Phase 1: Build (cargo build --release)"
69+
echo "============================================================================="
70+
71+
log_info "Building workspace..."
72+
if cargo build --release 2>&1; then
73+
log_success "Build completed successfully"
74+
else
75+
log_failure "Build failed"
76+
exit 1
77+
fi
78+
79+
# =============================================================================
80+
# Phase 2: Unit Tests
81+
# =============================================================================
82+
echo ""
83+
echo "============================================================================="
84+
echo "Phase 2: Unit Tests (cargo test --workspace)"
85+
echo "============================================================================="
86+
87+
log_info "Running unit tests..."
88+
if cargo test --workspace --release 2>&1 | tee /tmp/unit_tests.log; then
89+
UNIT_RESULTS=$(grep -E "^test result:" /tmp/unit_tests.log | tail -1)
90+
log_success "Unit tests completed: $UNIT_RESULTS"
91+
else
92+
log_failure "Unit tests failed"
93+
fi
94+
95+
# =============================================================================
96+
# Phase 3: Docker Integration Tests
97+
# =============================================================================
98+
echo ""
99+
echo "============================================================================="
100+
echo "Phase 3: Docker Integration Tests"
101+
echo "============================================================================="
102+
103+
# Check Docker availability
104+
if docker info > /dev/null 2>&1; then
105+
log_info "Docker daemon available"
106+
107+
# Secure Container Runtime tests
108+
log_info "Running secure-container-runtime Docker tests..."
109+
if cargo test -p secure-container-runtime --release -- --ignored 2>&1 | tee /tmp/docker_tests.log; then
110+
log_success "Secure container runtime Docker tests passed"
111+
else
112+
log_failure "Secure container runtime Docker tests failed"
113+
fi
114+
115+
# Challenge Orchestrator Docker tests
116+
log_info "Running challenge-orchestrator Docker tests..."
117+
if cargo test -p challenge-orchestrator --release -- --ignored 2>&1; then
118+
log_success "Challenge orchestrator Docker tests passed"
119+
else
120+
log_failure "Challenge orchestrator Docker tests failed"
121+
fi
122+
else
123+
log_skip "Docker not available, skipping Docker tests"
124+
fi
125+
126+
# =============================================================================
127+
# Phase 4: Bittensor Integration Tests
128+
# =============================================================================
129+
echo ""
130+
echo "============================================================================="
131+
echo "Phase 4: Bittensor Integration Tests"
132+
echo "============================================================================="
133+
134+
log_info "Running Bittensor integration tests (requires network)..."
135+
if timeout 120 cargo test -p platform-bittensor --release -- --ignored 2>&1; then
136+
log_success "Bittensor integration tests passed"
137+
else
138+
log_warning "Bittensor integration tests failed or timed out (may require network)"
139+
fi
140+
141+
# =============================================================================
142+
# Phase 5: Security Policy Tests
143+
# =============================================================================
144+
echo ""
145+
echo "============================================================================="
146+
echo "Phase 5: Security Policy Tests"
147+
echo "============================================================================="
148+
149+
log_info "Verifying security policies..."
150+
151+
# Test that Docker socket mounting is blocked
152+
log_info "Testing Docker socket mount blocking..."
153+
if cargo test -p secure-container-runtime test_default_policy_blocks_docker_socket --release 2>&1; then
154+
log_success "Docker socket mount blocking verified"
155+
else
156+
log_failure "Docker socket mount blocking test failed"
157+
fi
158+
159+
# Test image whitelist
160+
log_info "Testing image whitelist enforcement..."
161+
if cargo test -p secure-container-runtime test_strict_policy_blocks_non_whitelisted_images --release 2>&1; then
162+
log_success "Image whitelist enforcement verified"
163+
else
164+
log_failure "Image whitelist enforcement test failed"
165+
fi
166+
167+
# Test resource limits
168+
log_info "Testing resource limit enforcement..."
169+
if cargo test -p secure-container-runtime test_policy_enforces_resource_limits --release 2>&1; then
170+
log_success "Resource limit enforcement verified"
171+
else
172+
log_failure "Resource limit enforcement test failed"
173+
fi
174+
175+
# =============================================================================
176+
# Phase 6: P2P Consensus Tests
177+
# =============================================================================
178+
echo ""
179+
echo "============================================================================="
180+
echo "Phase 6: P2P Consensus Tests"
181+
echo "============================================================================="
182+
183+
log_info "Running P2P consensus unit tests..."
184+
if cargo test -p platform-p2p-consensus --release 2>&1 | tee /tmp/p2p_tests.log; then
185+
P2P_RESULTS=$(grep -E "^test result:" /tmp/p2p_tests.log | tail -1)
186+
log_success "P2P consensus tests: $P2P_RESULTS"
187+
else
188+
log_failure "P2P consensus tests failed"
189+
fi
190+
191+
# =============================================================================
192+
# Phase 7: Storage Tests
193+
# =============================================================================
194+
echo ""
195+
echo "============================================================================="
196+
echo "Phase 7: Storage Tests"
197+
echo "============================================================================="
198+
199+
log_info "Running storage tests..."
200+
if cargo test -p platform-storage --release 2>&1; then
201+
log_success "Storage tests passed"
202+
else
203+
log_failure "Storage tests failed"
204+
fi
205+
206+
log_info "Running distributed storage tests..."
207+
if cargo test -p platform-distributed-storage --release 2>&1; then
208+
log_success "Distributed storage tests passed"
209+
else
210+
log_failure "Distributed storage tests failed"
211+
fi
212+
213+
# =============================================================================
214+
# Summary
215+
# =============================================================================
216+
echo ""
217+
echo "============================================================================="
218+
echo " Test Summary"
219+
echo "============================================================================="
220+
echo ""
221+
echo -e " ${GREEN}Passed:${NC} $PASSED"
222+
echo -e " ${RED}Failed:${NC} $FAILED"
223+
echo -e " ${YELLOW}Skipped:${NC} $SKIPPED"
224+
echo ""
225+
226+
if [ $FAILED -eq 0 ]; then
227+
echo -e "${GREEN}All tests passed!${NC}"
228+
exit 0
229+
else
230+
echo -e "${RED}Some tests failed. Please review the output above.${NC}"
231+
exit 1
232+
fi
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# =============================================================================
2+
# Platform Test Validator Docker Image
3+
# =============================================================================
4+
# Lightweight build for testing multi-validator P2P network
5+
# Uses pre-built binary from cargo build --release
6+
# =============================================================================
7+
8+
FROM rust:1.92-bookworm AS builder
9+
10+
# Install dependencies
11+
RUN apt-get update && apt-get install -y \
12+
pkg-config \
13+
libssl-dev \
14+
protobuf-compiler \
15+
cmake \
16+
clang \
17+
libclang-dev \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
WORKDIR /app
21+
22+
# Copy workspace files
23+
COPY Cargo.toml Cargo.lock ./
24+
COPY crates ./crates
25+
COPY bins ./bins
26+
COPY tests ./tests
27+
28+
# Build release binary
29+
RUN cargo build --release --bin validator-node
30+
31+
# Runtime stage
32+
FROM debian:bookworm-slim
33+
34+
# Install runtime dependencies
35+
RUN apt-get update && apt-get install -y \
36+
ca-certificates \
37+
libssl3 \
38+
curl \
39+
&& rm -rf /var/lib/apt/lists/*
40+
41+
# Copy binary from builder
42+
COPY --from=builder /app/target/release/validator-node /usr/local/bin/validator-node
43+
44+
# Create data directory
45+
RUN mkdir -p /data && chmod 755 /data
46+
47+
# Environment defaults
48+
ENV RUST_LOG=info,validator_node=debug,platform_p2p_consensus=info
49+
ENV DATA_DIR=/data
50+
ENV NETUID=100
51+
52+
# Expose P2P port
53+
EXPOSE 9000
54+
55+
# Health check
56+
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
57+
CMD test -e /data/distributed.db || exit 1
58+
59+
# Entry point script to handle arguments
60+
COPY tests/docker/entrypoint-test.sh /entrypoint.sh
61+
RUN chmod +x /entrypoint.sh
62+
63+
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)