aboutsummaryrefslogtreecommitdiff
path: root/internal/game/owner_goexit_test.go
blob: 5be643fae08b39deee4945844dec248ef6a7162d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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")
	}
}