Close Leaked goroutine

This commit is contained in:
giongto35 2019-05-08 23:59:47 +08:00
parent 322b5bffe0
commit 0eea6cfcc8
11 changed files with 144 additions and 72 deletions

View file

@ -6,6 +6,7 @@ import (
"math/rand"
"net/http"
_ "net/http/pprof"
"runtime"
"strings"
"time"
@ -65,12 +66,22 @@ func initializeServer() {
http.ListenAndServe(":"+*config.Port, nil)
}
func monitor() {
c := time.Tick(time.Second)
for range c {
log.Printf("#goroutines: %d\n", runtime.NumGoroutine())
}
}
func main() {
flag.Parse()
log.Println("Usage: ./game [-debug]")
rand.Seed(time.Now().UTC().UnixNano())
//if *config.IsMonitor {
go monitor()
//}
// There are two server mode
// Overlord is coordinator. If the OvelordHost Param is `overlord`, we spawn a new host as Overlord.
// else we spawn new server as normal server connecting to OverlordHost.

View file

@ -7,6 +7,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/giongto35/cloud-game/cws"
"github.com/giongto35/cloud-game/handler"
@ -159,6 +160,7 @@ func TestSingleServerNoOverlord(t *testing.T) {
fmt.Println("RoomID should not be empty")
t.Fail()
}
time.Sleep(time.Second)
fmt.Println("Done")
}
@ -192,6 +194,7 @@ func TestSingleServerOneOverlord(t *testing.T) {
fmt.Println("RoomID should not be empty")
t.Fail()
}
time.Sleep(time.Second)
fmt.Println("Done")
}
@ -262,6 +265,7 @@ func TestTwoServerOneOverlord(t *testing.T) {
})
// If receive roomID, the server is running correctly
time.Sleep(time.Second)
fmt.Println("Done")
}
@ -319,6 +323,7 @@ func TestReconnectRoomNoOverlord(t *testing.T) {
t.Fail()
}
time.Sleep(time.Second)
fmt.Println("Done")
}