package main import "testing" // TestHubShutdown checks that shutdown() closes every connected client's send // channel (which ends its writer and closes the socket, so browsers reconnect). func TestHubShutdown(t *testing.T) { h := newHub() go h.run() c := &client{send: make(chan []byte, 1)} h.register <- c h.shutdown() select { case _, ok := <-c.send: if ok { t.Fatal("send channel should be closed after shutdown") } default: t.Fatal("send channel not closed after shutdown") } }