package game // Regression: network input may arrive on a connection goroutine at any // moment, including while the tick-driven logout countdown (owner goroutine) // transitions the session to the character menu. The dispatch read // sess.State as a plain field, which the race detector flagged; the state is // now an atomic on net.Session. This test drives both sides concurrently and // must run clean under -race. import ( "testing" "time" ) func TestInputDuringLogoutCountdownIsRaceFree(t *testing.T) { h := newHarness(t) h.seedAccount("alice") h.seedCharacter("alice", "alice") sess, _ := h.connect("alice") h.g.RunOnOwner(func() { h.g.beginQuitCountdown(sess) }) // Pump input while the countdown ticks toward the state change to the // character menu (and past it, when the countdown completes early). deadline := time.Now().Add(100 * time.Millisecond) for time.Now().Before(deadline) { h.g.HandleSessionOnOwner(sess, "notacommand") } h.barrier() }