# π§ͺ Platform Detection Stress Testing Guide
This guide provides comprehensive stress testing for the intelligent platform detection system to ensure it works reliably for developers across different environments and scenarios.
## π― Testing Overview
We provide **two levels of stress testing**:
1. **π Quick Stress Test** - Fast, developer-friendly validation (30 seconds)
2. **π¬ Comprehensive Stress Test** - Full validation suite (5-10 minutes)
## π Quick Stress Test (Recommended for Daily Development)
### Usage
```bash
npm run docker:stress-test:quick
```
### What it Tests
- β
Architecture detection accuracy
- β
Docker capability detection
- β
Configuration selection logic
- β
Docker environment availability
- β
Detection consistency across multiple runs
- β
File generation and validation
- β
Docker Compose syntax validation
- β
Container startup/shutdown cycle
### Expected Results
- **π Excellent (90-100%)**: Platform detection working perfectly
- **β
Good (75-89%)**: Working well with minor issues
- **β οΈ Warning (50-74%)**: Some issues need attention
- **β Critical (<50%)**: Major issues requiring fixes
### Example Output
```text
β‘ Quick Platform Detection Stress Test
========================================
β
Architecture Detection (0ms)
β
Docker Capabilities (779ms)
β
Configuration Selection (421ms)
β
Docker Environment (17ms)
β
Detection Consistency (0ms)
β
File Generation (572ms)
β
Docker Compose Validation (61ms)
β
Container Startup Test (10726ms)
π Results
===========
β
Passed: 8/8
β Failed: 0/8
π Success Rate: 100%
π EXCELLENT - Platform detection is working perfectly!
π‘ Developer Tips:
π Apple Silicon detected:
β
Rosetta 2 emulation is working - optimal configuration selected
π§ͺ Run full stress test: npm run docker:stress-test
π View configuration: cat test/docker/.platform-config.json
```
## π¬ Comprehensive Stress Test
### Comprehensive Usage
```bash
npm run docker:stress-test
```
### Comprehensive Test Coverage
#### 1. Detection Logic Validation
- Architecture detection accuracy
- Docker capabilities detection
- Configuration selection logic
- Detection consistency across multiple runs
#### 2. Docker Capability Testing
- Docker daemon availability
- Platform support verification (Buildx)
- AMD64 emulation testing
- Docker Compose availability
#### 3. Configuration Generation Testing
- YAML generation accuracy
- File writing and reading operations
- Rapid generation stress testing (10 iterations)
#### 4. Docker Container Lifecycle Testing
- Container startup with generated config
- Container health check validation
- Platform warning verification (no warnings should appear)
- Container shutdown testing
#### 5. Edge Case Handling
- Simulated Docker unavailability
- Unknown architecture fallback handling
- File system permissions testing
#### 6. Performance & Reliability Testing
- Detection speed benchmarking (50 iterations)
- Memory usage stability testing
- Concurrent detection testing (10 parallel requests)
### Comprehensive Test Results
The comprehensive test provides detailed insights into:
- Individual test results with timing
- Performance metrics and bottlenecks
- Failed test details with error messages
- Memory usage patterns
- Concurrent operation stability
## π― When to Use Each Test
### Use Quick Stress Test For
- **Daily development validation**
- **Pre-commit testing**
- **Quick confidence checks**
- **CI/CD integration**
- **New environment setup validation**
### Use Comprehensive Stress Test For
- **Pre-release validation**
- **New feature development**
- **Performance regression testing**
- **Cross-platform validation**
- **Deep troubleshooting**
## ποΈ Developer Workflow Integration
### Daily Development
```bash
# Before starting work
npm run docker:stress-test:quick
# After platform detection changes
npm run docker:stress-test:quick
```
### Pre-Release Validation
```bash
# Full validation before release
npm run docker:stress-test
# Validate on different architectures if possible
# - Intel Mac developer machine
# - Apple Silicon Mac
# - Linux CI/CD environment
```
### Troubleshooting
```bash
# If quick test fails, run comprehensive test for details
npm run docker:stress-test:quick
npm run docker:stress-test # If issues detected
# Check generated configuration
cat test/docker/.platform-config.json
# Verify Docker environment
docker --version
docker system info
```
## π Architecture-Specific Results
### Apple Silicon (ARM64) Expected Results
```text
π Detected platform: darwin, architecture: arm64
β
Docker capabilities: AMD64 support via Rosetta 2
β
Selected: SQL Server 2022 with linux/amd64 platform override
β
Performance: Very Good (emulated via Rosetta 2)
β
No platform mismatch warnings in container logs
```
### Intel Mac (AMD64) Expected Results
```text
π Detected platform: darwin, architecture: x64
β
Docker capabilities: Native AMD64 support
β
Selected: SQL Server 2022 native (no platform override)
β
Performance: Excellent (native)
β
No platform warnings
```
### Linux (Various) Expected Results
```text
π Detected platform: linux, architecture: [x64|arm64]
β
Docker capabilities: Platform-appropriate support
β
Selected: Optimal configuration for detected architecture
β
Performance: Architecture-dependent
```
## π¨ Common Issues and Solutions
### Docker Not Available
```text
β Docker Environment - Docker daemon not available
Solutions:
π₯ Install Docker Desktop: https://docs.docker.com/get-docker/
π Start Docker Desktop application
π§ Verify with: docker --version
```
### Platform Detection Inconsistent
```text
β Detection Consistency - Inconsistent detection results
Solutions:
π Restart Docker Desktop
π§Ή Clear Docker cache: docker system prune
π§ Check system resources (CPU/Memory pressure)
```
### Container Startup Failures
```text
β Container Startup Test - Container not running
Solutions:
π Check port availability: lsof -i :1433
π§Ή Clean Docker state: npm run docker:clean
π Verify Docker Compose: docker-compose -f test/docker/docker-compose.yml config
```
### AMD64 Emulation Issues
```text
β οΈ AMD64 Emulation - AMD64 emulation may have issues
Solutions (Apple Silicon):
π§ Update Docker Desktop to latest version
βοΈ Enable "Use Rosetta for x86/amd64 emulation" in Docker settings
π Restart Docker Desktop
```
## π Performance Benchmarks
### Expected Performance Characteristics
#### Quick Stress Test
- **Total Duration**: 15-45 seconds
- **Architecture Detection**: <1ms
- **Docker Capabilities**: 100-1000ms (first run), <100ms (subsequent)
- **Container Startup**: 5-15 seconds
- **Memory Usage**: <50MB additional
#### Comprehensive Stress Test
- **Total Duration**: 5-10 minutes
- **Detection Performance**: <1000ms average for 50 iterations
- **Memory Stability**: <10MB increase over 100 iterations
- **Concurrent Operations**: >90% success rate with 10 parallel requests
### Performance Red Flags
- Detection taking >5 seconds consistently
- Memory usage increasing >50MB during testing
- Container startup taking >30 seconds
- Success rates <75% in stress testing
## π§ Advanced Testing Scenarios
### Testing Different Configurations
```bash
# Force different configurations for testing
export FORCE_SQL_IMAGE="mcr.microsoft.com/azure-sql-edge:latest"
npm run docker:stress-test:quick
# Skip detection for testing existing config
export SKIP_PLATFORM_DETECTION=true
npm run docker:start
```
### Testing Edge Cases
```bash
# Test with limited resources
docker run --memory=500m --cpus=0.5 mcr.microsoft.com/mssql/server:2022-latest@sha256:d1d2fa72786dd255f25ef85a4862510db1d4f9aa844519db565136311c0d7c7f
# Test with different Docker Compose versions
docker-compose version
docker compose version
```
### Multi-Platform Testing
If you have access to different architectures:
1. **Intel Mac**: Test native AMD64 performance
2. **Apple Silicon**: Test Rosetta 2 emulation
3. **Linux x86_64**: Test production-like environment
4. **Linux ARM64**: Test native ARM64 with SQL Edge fallback
## π Test Results Analysis
### Interpreting Results
- **100% Pass Rate**: Excellent, ready for production
- **90-99% Pass Rate**: Very good, minor optimizations possible
- **75-89% Pass Rate**: Good, some environment-specific issues
- **<75% Pass Rate**: Investigate environment setup
### Result Files
The comprehensive stress test generates detailed results:
```bash
# View detailed results
cat test/docker/.stress-test-results.json
# Key metrics to monitor
- summary.successRate
- environment.platform/arch
- performance insights
- failed test details
```
## π Success Criteria
Your platform detection is working correctly when:
β
**Quick stress test passes with >90% success rate**
β
**No platform mismatch warnings in Docker logs**
β
**Consistent detection across multiple runs**
β
**Container starts and stops cleanly**
β
**Generated Docker Compose is syntactically valid**
β
**Performance is within expected benchmarks**
β
**Memory usage remains stable**
## π Related Documentation
- **[Platform Detection Guide](PLATFORM-DETECTION.md)** - How the detection system works
- **[Docker Testing Setup](README.md)** - Complete Docker testing guide
- **[Manual Integration Tests](../integration/manual/README.md)** - Database testing procedures
---
> **π‘ Pro Tip**: Run the quick stress test whenever you switch machines, update Docker, or make changes to the
> platform detection system. It's designed to catch issues early and provide confidence in your development environment.