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() } }