mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
feat(multiplayer): cap websocket connections per player
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package api
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEventHubCapsConnectionsPerPlayerAndReleasesCapacity(t *testing.T) {
|
||||
hub := newEventHub()
|
||||
first := hub.subscribe("player-1")
|
||||
second := hub.subscribe("player-1")
|
||||
if first == nil || second == nil {
|
||||
t.Fatal("connection within per-player cap was rejected")
|
||||
}
|
||||
if third := hub.subscribe("player-1"); third != nil {
|
||||
t.Fatal("connection over per-player cap was accepted")
|
||||
}
|
||||
hub.unsubscribe(first)
|
||||
if third := hub.subscribe("player-1"); third == nil {
|
||||
t.Fatal("released connection capacity was not reusable")
|
||||
} else {
|
||||
hub.unsubscribe(third)
|
||||
}
|
||||
hub.unsubscribe(second)
|
||||
}
|
||||
Reference in New Issue
Block a user