From 396c3facb8287b9a34076cae8f3d7b300d366d99 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 15 Sep 2026 14:18:14 -0400 Subject: fix: atomic saves, casino RNG/config isolation, tick lifecycle --- internal/engine/lifecycle_test.go | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 internal/engine/lifecycle_test.go (limited to 'internal/engine/lifecycle_test.go') diff --git a/internal/engine/lifecycle_test.go b/internal/engine/lifecycle_test.go new file mode 100644 index 0000000..8cea97f --- /dev/null +++ b/internal/engine/lifecycle_test.go @@ -0,0 +1,40 @@ +package engine + +import ( + "sync" + "testing" +) + +func TestConcurrentTicksAreSerialized(t *testing.T) { + e := New() + count := 0 + e.Subscribe(1, func() bool { + count++ // safe only when callbacks have a single owner + return true + }) + var wg sync.WaitGroup + for i := 0; i < 8; i++ { + wg.Add(1) + go func() { + defer wg.Done() + for j := 0; j < 100; j++ { + e.Tick() + } + }() + } + wg.Wait() + if count != 800 { + t.Fatalf("lost ticks: got %d, want 800", count) + } +} + +func TestStopIsIdempotentAndRestartable(t *testing.T) { + e := New() + e.Stop() + defer e.Stop() + for i := 0; i < 100; i++ { + e.Start(60000) + e.Stop() + e.Stop() + } +} -- cgit v1.2.3