tests work for GOMAXPROCS>1
This commit is contained in:
parent
922acbdb54
commit
aaaff34448
4
game.go
4
game.go
@ -17,6 +17,7 @@ type game struct {
|
|||||||
spectators map[*Spectator]bool
|
spectators map[*Spectator]bool
|
||||||
sregister chan *Spectator
|
sregister chan *Spectator
|
||||||
sunregister chan *Spectator
|
sunregister chan *Spectator
|
||||||
|
kill chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGame() *game {
|
func NewGame() *game {
|
||||||
@ -30,6 +31,7 @@ func NewGame() *game {
|
|||||||
spectators: make(map[*Spectator]bool),
|
spectators: make(map[*Spectator]bool),
|
||||||
sregister: make(chan *Spectator),
|
sregister: make(chan *Spectator),
|
||||||
sunregister: make(chan *Spectator),
|
sunregister: make(chan *Spectator),
|
||||||
|
kill: make(chan bool),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +68,8 @@ func (g *game) run() {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
case <-g.kill:
|
||||||
|
return
|
||||||
case p := <-g.register:
|
case p := <-g.register:
|
||||||
g.players[p] = true
|
g.players[p] = true
|
||||||
case p := <-g.unregister:
|
case p := <-g.unregister:
|
||||||
|
18
id_test.go
Normal file
18
id_test.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIDGenerator(t *testing.T) {
|
||||||
|
cache := make(map[string]bool)
|
||||||
|
var cur string
|
||||||
|
gg := NewIdGenerator()
|
||||||
|
for i := 0; i < 10000; i++ {
|
||||||
|
cur = gg.Hash()
|
||||||
|
if _, ok := cache[cur]; ok {
|
||||||
|
t.Errorf("unexpected duplicate key")
|
||||||
|
}
|
||||||
|
cache[cur] = true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user