@@ -24,6 +24,7 @@ import cz.vutbr.fit.interlockSim.testutil.withMessage
2424import cz.vutbr.fit.interlockSim.testutil.KoinTestBase
2525import cz.vutbr.fit.interlockSim.testutil.buildLinearTrack
2626import cz.vutbr.fit.interlockSim.testutil.buildMinimal
27+ import org.junit.jupiter.api.Disabled
2728import org.junit.jupiter.api.DisplayName
2829import org.junit.jupiter.api.Nested
2930import org.junit.jupiter.api.Tag
@@ -38,37 +39,37 @@ import java.util.concurrent.atomic.AtomicReference
3839/* *
3940 * Comprehensive race condition tests for concurrent access scenarios.
4041 *
41- * Tests the thread safety of core railway interlocking operations under
42- * concurrent access patterns. These advanced tests validate that public APIs
43- * properly handle simultaneous operations from multiple threads.
42+ * **IMPORTANT: Tests in this class are DISABLED by design.**
4443 *
45- * Key scenarios tested:
46- * 1. Concurrent path reservation attempts
47- * 2. Simultaneous switch state changes
48- * 3. Concurrent track occupancy updates
49- * 4. Thread safety of Context modifications
44+ * These tests demonstrate race conditions that occur when Context classes are
45+ * accessed concurrently. However, Context is intentionally NOT thread-safe:
5046 *
51- * Test organization:
52- * - Concurrent path operations (reservation, setup, cancellation)
53- * - Switch state modifications under concurrent access
54- * - Track occupancy and entry/leave operations
55- * - Context grid modifications during concurrent access
47+ * ## Design Decision (Option 1)
5648 *
57- * Safety Properties Validated:
58- * - SI-4: Path reservation atomicity (all-or-nothing)
59- * - SI-5: Switch locking during path use (no state corruption)
60- * - SI-1: No collision detection (track occupancy integrity)
61- * - Data consistency under concurrent access
49+ * Context and its implementations (DefaultContext, EditingContext, SimulationContext)
50+ * are documented as NOT thread-safe. Multi-threaded access is not supported.
6251 *
63- * Thread Safety Strategy :
64- * - Use CountDownLatch for precise synchronization
65- * - Use AtomicInteger/AtomicBoolean for thread-safe counters
66- * - Use CopyOnWriteArrayList for thread-safe exception collection
67- * - Avoid timing-dependent assertions (use latches instead)
68- * - Conservative API testing (test only public methods)
52+ * ### Rationale :
53+ * 1. Railway simulations are inherently sequential (discrete event model)
54+ * 2. The jDisco framework is single-threaded by design
55+ * 3. No current use cases require concurrent Context access
56+ * 4. Thread-safety would add unnecessary complexity and performance overhead
57+ * 5. Aligns with KISS principle
6958 *
70- * Coverage Target: ~50-75 instructions
59+ * ### Race Conditions Documented:
60+ * - NullPointerException in grid access during concurrent modifications
61+ * - ArrayIndexOutOfBoundsException in cell operations
62+ * - ConcurrentModificationException in listener notifications
7163 *
64+ * These tests remain in the codebase to:
65+ * 1. Document known race conditions if thread-safety is attempted in the future
66+ * 2. Provide evidence for the design decision to not implement thread-safety
67+ * 3. Serve as integration tests if the design decision is revisited
68+ *
69+ * **Usage:** Do not enable these tests unless implementing thread-safety (Option 2).
70+ *
71+ * @see cz.vutbr.fit.interlockSim.context.Context
72+ * @see cz.vutbr.fit.interlockSim.context.DefaultContext
7273 * @since 2026-01 (Phase 6 advanced testing)
7374 * @tag integration-test
7475 */
@@ -632,8 +633,19 @@ class RaceConditionTest : KoinTestBase() {
632633 inner class ConcurrentContextModifications {
633634 /* *
634635 * Test concurrent cell placement and retrieval from the context grid.
636+ *
637+ * **DISABLED: Context is not thread-safe by design.**
638+ *
639+ * This test demonstrates ArrayIndexOutOfBoundsException that occurs when
640+ * multiple threads concurrently access the Context grid. This is expected
641+ * behavior as Context is intentionally not thread-safe.
642+ *
643+ * See Context documentation for rationale and usage guidelines.
644+ *
645+ * @see <a href="https://github.com/bedaHovorka/interlockSim/issues/28">Issue #28</a>
635646 */
636647 @Test
648+ @Disabled(" Context is not thread-safe by design (Issue #28). Do not use from multiple threads." )
637649 @DisplayName(" Concurrent cell operations on context grid are thread-safe" )
638650 fun concurrentCellOperations_contextGrid_threadSafe () {
639651 // Arrange
@@ -692,8 +704,19 @@ class RaceConditionTest : KoinTestBase() {
692704
693705 /* *
694706 * Test concurrent context modifications maintain grid consistency.
707+ *
708+ * **DISABLED: Context is not thread-safe by design.**
709+ *
710+ * This test demonstrates NullPointerException that occurs when multiple
711+ * threads concurrently modify the Context grid. This is expected behavior
712+ * as Context is intentionally not thread-safe.
713+ *
714+ * See Context documentation for rationale and usage guidelines.
715+ *
716+ * @see <a href="https://github.com/bedaHovorka/interlockSim/issues/28">Issue #28</a>
695717 */
696718 @Test
719+ @Disabled(" Context is not thread-safe by design (Issue #28). Do not use from multiple threads." )
697720 @DisplayName(" Concurrent context modifications maintain grid consistency" )
698721 fun concurrentContextMod_maintainsGridConsistency () {
699722 // Arrange
@@ -950,8 +973,19 @@ class RaceConditionTest : KoinTestBase() {
950973 /* *
951974 * Test that multiple listener registrations and removals work correctly
952975 * under concurrent grid modifications.
976+ *
977+ * **DISABLED: Context is not thread-safe by design.**
978+ *
979+ * This test demonstrates ConcurrentModificationException that occurs when
980+ * listener notifications happen concurrently with grid modifications. This
981+ * is expected behavior as Context is intentionally not thread-safe.
982+ *
983+ * See Context documentation for rationale and usage guidelines.
984+ *
985+ * @see <a href="https://github.com/bedaHovorka/interlockSim/issues/28">Issue #28</a>
953986 */
954987 @Test
988+ @Disabled(" Context is not thread-safe by design (Issue #28). Do not use from multiple threads." )
955989 @DisplayName(" Listeners and grid modifications work correctly concurrently" )
956990 fun listenersAndGridMods_workConcurrently () {
957991 // Arrange
0 commit comments