Browse Source

tests work for GOMAXPROCS>1

master
Stephen McQuay 7 years ago
parent
commit
aaaff34448
3 changed files with 23 additions and 1 deletions
  1. +4
    -0
      game.go
  2. +1
    -1
      id.go
  3. +18
    -0
      id_test.go

+ 4
- 0
game.go View File

@ -17,6 +17,7 @@ type game struct {
spectators map[*Spectator]bool
sregister chan *Spectator
sunregister chan *Spectator
kill chan bool
}
func NewGame() *game {
@ -30,6 +31,7 @@ func NewGame() *game {
spectators: make(map[*Spectator]bool),
sregister: make(chan *Spectator),
sunregister: make(chan *Spectator),
kill: make(chan bool),
}
}
@ -66,6 +68,8 @@ func (g *game) run() {
for {
select {
case <-g.kill:
return
case p := <-g.register:
g.players[p] = true
case p := <-g.unregister:

+ 1
- 1
id.go View File

@ -15,7 +15,7 @@ func NewIdGenerator() *IdGenerator {
g := IdGenerator{}
g.id = make(chan int64)
go func() {
var i int64
var i int64
for i = 0; ; i++ {
g.id <- i
}

+ 18
- 0
id_test.go View 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…
Cancel
Save