diff --git a/services/xmppsService.go b/services/xmppsService.go index 278c690..5460f3a 100644 --- a/services/xmppsService.go +++ b/services/xmppsService.go @@ -8,6 +8,7 @@ import ( "math/rand" "os" "strconv" + "sync" "time" appConfig "github.com/xmpploadtesting/config" @@ -91,8 +92,10 @@ func Init() { log.Printf("Client credentials length %v", len(clientCredentials)) xmppService.XMPPClients = make([]XMPPClient, 0) + var wg sync.WaitGroup for _, credential := range clientCredentials { + wg.Add(1) log.Printf("Host %v", credential.Host+":"+strconv.Itoa(credential.Port)) log.Printf("Jid %v", credential.Jid+"@"+credential.Host) log.Printf("Port %v", credential.Port) @@ -114,6 +117,7 @@ func Init() { } go func() { + defer wg.Done() client, err := xmpp.NewClient(&xmppClient.Config, xmppService.Router, errorHandler) @@ -133,8 +137,10 @@ func Init() { }() } - // Delay For two seccond to allow all clients to connect - time.Sleep(time.Duration(2000000000)) + // // Delay For two seccond to allow all clients to connect + // time.Sleep(time.Duration(2000000000)) + // Wait untill all client connections are open sucessfuly + wg.Wait() }