修复冻结用户强制下线
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package chathub
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDisconnectUserClosesAllConnections(t *testing.T) {
|
||||
hub := NewHub(nil)
|
||||
first := hub.Subscribe("user", 7)
|
||||
second := hub.Subscribe("user", 7)
|
||||
hub.Subscribe("user", 8)
|
||||
|
||||
hub.DisconnectUser(7)
|
||||
for name, ch := range map[string]<-chan *ChatEvent{"first": first, "second": second} {
|
||||
select {
|
||||
case _, ok := <-ch:
|
||||
if ok {
|
||||
t.Fatalf("%s connection was not closed", name)
|
||||
}
|
||||
default:
|
||||
t.Fatalf("%s connection did not close immediately", name)
|
||||
}
|
||||
}
|
||||
if got := hub.OnlineCount(); got != 1 {
|
||||
t.Fatalf("online connection count = %d, want 1", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user