We test READERS, not WRITERS.
The sensor simulator (main.py) is the ONLY source of truth for writing sensor data. All testing should focus on validating that external systems can successfully read from the database while the real sensor simulator is writing.
- Single Source of Truth: Only
main.pyknows the correct schema, data patterns, and business logic - Real-World Testing: Tests validate actual production behavior, not mocked scenarios
- Schema Consistency: Prevents drift between test data and production data
- Simplicity: No need to maintain separate mock data generators
# Start the real sensor in one terminal (ALWAYS start fresh)
uv run main.py # Creates new database - this is correct!
# In another terminal, test readers (always read-only)
uv run scripts/testing/test_readers.py -r 10- ALWAYS let the sensor create a fresh database
- Old databases may have schema differences
- Mixing schemas causes corruption
- Test readers ALWAYS use
mode=rofor safety
# DON'T DO THIS - Never create fake sensor data
conn.execute("INSERT INTO sensor_readings VALUES (...)")test_readers.py- Tests concurrent reading while sensor writestest_readers_containerized.py- Tests containerized readersread_safe.py- Example of safe reading patterns
These scripts currently violate our philosophy by creating mock data:
stress_test.py- Should be updated to use real sensortest_containers_rw.py- Should be updated to use real sensor
- All write operations must come from
main.py - Test scripts should ONLY read from the database
- Performance tests should start multiple instances of the real sensor
- Container tests should use the actual sensor Docker image
- Test databases must use temporary directories, never
data/ - Only sensor_data.db should exist in the
data/directory
- No schema drift between tests and production
- Realistic testing of actual sensor behavior
- Simpler codebase with no mock data generators
- Better validation of real-world scenarios
Scripts that need updating to follow this philosophy:
- Remove INSERT statements from test scripts
- Replace with calls to start the real sensor
- Update documentation to reflect this approach