Add comprehensive concurrent compilation and hot-reload testing infrastructure
to validate thread safety and file stability during race conditions.
## New Components
### AutoCompiler Helper (tests/helpers/AutoCompiler.{h,cpp})
- Automatically modifies source files to bump version numbers
- Compiles modules repeatedly on separate thread (15 iterations @ 1s interval)
- Tracks compilation success/failure rates with atomic counters
- Thread-safe compilation statistics
### Race Condition Test (tests/integration/test_04_race_condition.cpp)
- **3 concurrent threads:**
- Compiler: Recompiles TestModule.so every 1 second
- FileWatcher: Detects .so changes and triggers hot-reload with mutex protection
- Engine: Runs at 60 FPS with try_lock to skip frames during reload
- Validates module integrity (health status, version, configuration)
- Tracks metrics: compilation rate, reload success, corrupted loads, crashes
- 90-second timeout with progress monitoring
### TestModule Enhancements (tests/modules/TestModule.cpp)
- Added global moduleVersion variable for AutoCompiler modification
- Version bumping support for reload validation
## Test Results (Initial Implementation)
```
Duration: 88s
Compilations: 15/15 (100%) ✅
Reloads: ~30 (100% success) ✅
Corrupted: 0 ✅
Crashes: 0 ✅
File Stability: 328ms avg (proves >100ms wait) ✅
```
## Known Issue (To Fix in Next Commit)
- Module versions not actually changing during reload
- setConfiguration() overwrites compiled version
- Reload mechanism validated but version bumping needs fix
## Files Modified
- tests/CMakeLists.txt: Add AutoCompiler to helpers, add test_04
- tests/modules/TestModule.cpp: Add version bumping support
- .gitignore: Add build/ and logs/
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
99 lines
2.6 KiB
C++
99 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <atomic>
|
|
#include <thread>
|
|
#include <functional>
|
|
|
|
namespace TestHelpers {
|
|
|
|
/**
|
|
* @brief Helper class to automatically compile a module repeatedly
|
|
*
|
|
* Designed to test race conditions during hot-reload by:
|
|
* - Modifying source files to bump version numbers
|
|
* - Triggering CMake builds repeatedly
|
|
* - Running on a separate thread with configurable interval
|
|
* - Tracking compilation success/failure rates
|
|
*/
|
|
class AutoCompiler {
|
|
public:
|
|
/**
|
|
* @param moduleName Name of the module to compile (e.g., "TestModule")
|
|
* @param buildDir Path to build directory (e.g., "build")
|
|
* @param sourcePath Path to the source file to modify (e.g., "tests/modules/TestModule.cpp")
|
|
*/
|
|
AutoCompiler(const std::string& moduleName,
|
|
const std::string& buildDir,
|
|
const std::string& sourcePath);
|
|
|
|
~AutoCompiler();
|
|
|
|
/**
|
|
* @brief Start auto-compilation thread
|
|
* @param iterations Total number of compilations to perform
|
|
* @param intervalMs Milliseconds between each compilation
|
|
*/
|
|
void start(int iterations, int intervalMs);
|
|
|
|
/**
|
|
* @brief Stop the compilation thread gracefully
|
|
*/
|
|
void stop();
|
|
|
|
/**
|
|
* @brief Get current iteration number
|
|
*/
|
|
int getCurrentIteration() const { return currentIteration_.load(); }
|
|
|
|
/**
|
|
* @brief Get number of successful compilations
|
|
*/
|
|
int getSuccessCount() const { return successCount_.load(); }
|
|
|
|
/**
|
|
* @brief Get number of failed compilations
|
|
*/
|
|
int getFailureCount() const { return failureCount_.load(); }
|
|
|
|
/**
|
|
* @brief Check if compilation thread is still running
|
|
*/
|
|
bool isRunning() const { return running_.load(); }
|
|
|
|
/**
|
|
* @brief Wait for all compilations to complete
|
|
*/
|
|
void waitForCompletion();
|
|
|
|
private:
|
|
/**
|
|
* @brief Modify source file to change version number
|
|
*/
|
|
void modifySourceVersion(int iteration);
|
|
|
|
/**
|
|
* @brief Compile the module using CMake
|
|
* @return true if compilation succeeded
|
|
*/
|
|
bool compile(int iteration);
|
|
|
|
/**
|
|
* @brief Main compilation loop (runs in separate thread)
|
|
*/
|
|
void compilationLoop(int iterations, int intervalMs);
|
|
|
|
std::string moduleName_;
|
|
std::string buildDir_;
|
|
std::string sourcePath_;
|
|
|
|
std::atomic<int> currentIteration_{0};
|
|
std::atomic<int> successCount_{0};
|
|
std::atomic<int> failureCount_{0};
|
|
std::atomic<bool> running_{false};
|
|
|
|
std::thread compilationThread_;
|
|
};
|
|
|
|
} // namespace TestHelpers
|