aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/lifecycle_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-15 14:18:14 -0400
committerhistoria <[not public]>2026-09-15 14:18:14 -0400
commit396c3facb8287b9a34076cae8f3d7b300d366d99 (patch)
tree941f280d051fac474fa68ca08318a8d16adc8d0f /internal/engine/lifecycle_test.go
parentb3568f03e4103dd46db2ccc680fbab0a6454d604 (diff)
downloadthehouseoficarus-396c3facb8287b9a34076cae8f3d7b300d366d99.tar.gz
fix: atomic saves, casino RNG/config isolation, tick lifecycle
Diffstat (limited to 'internal/engine/lifecycle_test.go')
-rw-r--r--internal/engine/lifecycle_test.go40
1 files changed, 40 insertions, 0 deletions
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()
+ }
+}