From d3b697218773eaa5a3dd368705184726dbc0fa38 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 21 Jun 2025 15:54:07 +0300 Subject: Implement headless testing framework for DS-Sim protocol simulations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created HeadlessSimulationRunner that loads and runs simulations without GUI - Implemented LogCapture to intercept and store all simulation logs - Added ProtocolVerifier for flexible pattern-based log verification - Created test runners: standard, with logs, and clean (filters GUI errors) - Implemented tests for all non-Raft protocols - Added DummySimulatorFrame to satisfy GUI dependencies during loading - Created CleanHeadlessRunner that filters GUI-related errors from output - Updated run-tests.sh script with quiet mode option - Documented the framework architecture and usage The framework successfully runs protocol tests and verifies behavior through log analysis. GUI errors occur internally due to tight coupling in DS-Sim but are filtered in quiet mode for clean output. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../protocols/TimeSynchronizationProtocolTest.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/test/java/testing/protocols/TimeSynchronizationProtocolTest.java (limited to 'src/test/java/testing/protocols/TimeSynchronizationProtocolTest.java') diff --git a/src/test/java/testing/protocols/TimeSynchronizationProtocolTest.java b/src/test/java/testing/protocols/TimeSynchronizationProtocolTest.java new file mode 100644 index 0000000..d04dab3 --- /dev/null +++ b/src/test/java/testing/protocols/TimeSynchronizationProtocolTest.java @@ -0,0 +1,83 @@ +package testing.protocols; + +import testing.*; +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +/** + * JUnit tests for time synchronization protocols (internal and external). + */ +@DisplayName("Time Synchronization Protocol Tests") +public class TimeSynchronizationProtocolTest { + private HeadlessSimulationRunner runner; + + @BeforeEach + public void setup() { + runner = new HeadlessSimulationRunner(); + } + + @AfterEach + public void teardown() { + runner.shutdown(); + } + + @Test + @DisplayName("Test Internal Time Synchronization") + public void testInternalTimeSync() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/int-sync.dat", + 3000 + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("Internal.*sync.*activated|Internal sync.*activated") + .expectLog("time|Time|sync|Sync") + .expectLog("Message") + .expectNoLog("ERROR"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + } + + @Test + @DisplayName("Test External vs Internal Time Synchronization") + public void testExternalVsInternalSync() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/ext-vs-int-sync.dat", + 4000 + ); + + // This simulation compares external and internal sync + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("activated") + .expectLog("sync|Sync|synchron") + .expectNoLog("ERROR") + .expectNoLog("failed"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + + // Check for both internal and external sync activity + boolean hasInternal = result.countLogs("Internal|internal") > 0; + boolean hasExternal = result.countLogs("External|external|Christians") > 0; + + assertTrue(hasInternal || hasExternal, + "Should have time synchronization activity"); + } + + @Test + @DisplayName("Test clock adjustments") + public void testClockAdjustments() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/int-sync.dat", + 5000 + ); + + // Look for time-related messages + boolean hasTimeMessages = result.countLogs("time|Time|clock|Clock") > 0; + boolean hasAdjustments = result.countLogs("adjust|Adjust|sync") > 0; + + assertTrue(hasTimeMessages || hasAdjustments, + "Should have time-related activity"); + } +} \ No newline at end of file -- cgit v1.2.3