25 lines
673 B
Go
25 lines
673 B
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestHubTracksOnlineAcrossMultipleDevices(t *testing.T) {
|
|
hub := NewHub()
|
|
first := &wsClient{userID: 7}
|
|
second := &wsClient{userID: 7}
|
|
if !hub.add(first) || !hub.online(7) {
|
|
t.Fatal("first socket must make the user online")
|
|
}
|
|
if hub.add(second) {
|
|
t.Fatal("a second device must not emit a duplicate online transition")
|
|
}
|
|
if hub.remove(first) || !hub.online(7) {
|
|
t.Fatal("one remaining device must keep the user online")
|
|
}
|
|
if !hub.remove(second) || hub.online(7) {
|
|
t.Fatal("the final socket must make the user offline")
|
|
}
|
|
if hub.remove(second) {
|
|
t.Fatal("a late duplicate close must not emit another transition")
|
|
}
|
|
}
|