Download this file
| 1 | package main |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // TestHubShutdown checks that shutdown() closes every connected client's send |
| 6 | // channel (which ends its writer and closes the socket, so browsers reconnect). |
| 7 | func TestHubShutdown(t *testing.T) { |
| 8 | h := newHub() |
| 9 | go h.run() |
| 10 | c := &client{send: make(chan []byte, 1)} |
| 11 | h.register <- c |
| 12 | h.shutdown() |
| 13 | select { |
| 14 | case _, ok := <-c.send: |
| 15 | if ok { |
| 16 | t.Fatal("send channel should be closed after shutdown") |
| 17 | } |
| 18 | default: |
| 19 | t.Fatal("send channel not closed after shutdown") |
| 20 | } |
| 21 | } |
| 22 | |