From 81bfa4a7f7eb93cd8685735c6ed09855960e440c Mon Sep 17 00:00:00 2001 From: Andy Librian Date: Thu, 1 Apr 2021 20:53:22 +0700 Subject: [PATCH] Simplify stopLoadTestIfNoWorkerRemaining --- pkg/server/server.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index c0306a5..1c114f4 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -173,10 +173,10 @@ func (s *Server) acceptWorkerConn(responseWriter http.ResponseWriter, req *http. logger.Infow("Worker connected", "name", name) + defer s.stopLoadTestIfNoWorkerRemaining() defer logger.Infow("Worker removed", "name", name) defer s.workerService.RemoveWorker(conn) defer conn.Close() - defer s.stopLoadTestIfNoWorkerRemaining() for { _, message, err := conn.ReadMessage() @@ -188,10 +188,8 @@ 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 { +func (s *Server) stopLoadTestIfNoWorkerRemaining() { + if len(s.workerService.workers) == 0 { s.loadTestState = messages.ServerStateStopped } }