package game import ( "runtime" "testing" "time" ) // A task that calls runtime.Goexit (t.Fatal on the owner goroutine) stops the // owner loop. Later RunOnOwner calls must return instead of blocking forever // waiting for a consumer that no longer exists. func TestOwnerGoexitDoesNotHangLaterTasks(t *testing.T) { h := newHarness(t) h.g.RunOnOwner(func() { runtime.Goexit() }) done := make(chan struct{}) go func() { defer close(done) h.g.RunOnOwner(func() {}) }() select { case <-done: case <-time.After(5 * time.Second): t.Fatal("RunOnOwner hung after the owner goroutine exited") } }