Skip to content

Commit

Permalink
Adding handler to stop loadtest when no worker is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ajiprabowo authored and andylibrian committed Apr 1, 2021
1 parent d767893 commit 81b217d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (s *Server) acceptWorkerConn(responseWriter http.ResponseWriter, req *http.
defer logger.Infow("Worker removed", "name", name)
defer s.workerService.RemoveWorker(conn)
defer conn.Close()
defer s.stopLoadTestIfNoWorkerRemaining()

for {
_, message, err := conn.ReadMessage()
Expand All @@ -187,6 +188,14 @@ func (s *Server) acceptWorkerConn(responseWriter http.ResponseWriter, req *http.
}
}

func (s *Server) stopLoadTestIfNoWorkerRemaining(){
val := len(s.workerService.workers) - 1
logger.Infow("Number of remaining workers: ", "", val)
if val == 0 {
s.loadTestState = messages.ServerStateStopped
}
}

func (s *Server) acceptNotificationConn(responseWriter http.ResponseWriter, req *http.Request, _ httprouter.Params) {
conn, err := s.upgrader.Upgrade(responseWriter, req, nil)
if err != nil {
Expand Down

0 comments on commit 81b217d

Please # to comment.