diff --git a/Makefile b/Makefile index 4935e4f..f6cec8a 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ vet: fmt go vet ./... test: - go test -v ./... + go test -count=1 -v ./... build: generate vet mkdir -p bin diff --git a/cmd/converge/converge.go b/cmd/converge/converge.go index d1aad5a..f23d921 100644 --- a/cmd/converge/converge.go +++ b/cmd/converge/converge.go @@ -213,13 +213,13 @@ func setupWebSockets(admin *matchmaker.MatchMaker, websessions *ui.WebSessions) sessionService := websocketutil.WebSocketService{ Handler: func(w http.ResponseWriter, r *http.Request, conn net.Conn) { ctx, cancel := context.WithCancel(context.Background()) - websession := websessions.NewSession(conn, ctx, cancel) + websession := websessions.NewSession(ctx, cancel, conn) defer websessions.SessionClosed(websession) location, err := ui.GetUserLocation(r) if err != nil { panic(err) } - websession.WriteNotifications(location, ctx, cancel) + websession.WriteNotifications(ctx, cancel, location) }, Text: true, } diff --git a/pkg/server/ui/websessions.go b/pkg/server/ui/websessions.go index 0075ee8..fd9c946 100644 --- a/pkg/server/ui/websessions.go +++ b/pkg/server/ui/websessions.go @@ -69,8 +69,7 @@ func (sessions *WebSessions) notifyWebSessions(notification *models.State) { } } -func (sessions *WebSessions) NewSession(wsConnection net.Conn, ctx context.Context, - cancel context.CancelFunc) *WebSession { +func (sessions *WebSessions) NewSession(ctx context.Context, cancel context.CancelFunc, wsConnection net.Conn) *WebSession { sessions.mutex.Lock() defer sessions.mutex.Unlock() session := &WebSession{ @@ -108,7 +107,7 @@ func (sessions *WebSessions) NewSession(wsConnection net.Conn, ctx context.Conte return session } -func (session *WebSession) WriteNotifications(location *time.Location, ctx context.Context, cancel context.CancelFunc) { +func (session *WebSession) WriteNotifications(ctx context.Context, cancel context.CancelFunc, location *time.Location) { timer := time.NewTicker(10 * time.Second) defer timer.Stop() // if for some reason we cannot send notifications to the web client then the context is canceled.