From 23b421bdc58ffab2425ba7cfde0bf3e9dc5d0189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Tue, 8 Oct 2019 19:31:14 +0200 Subject: [PATCH] Fix provision tool connect error handling (#879) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dušan Borovčanin --- tools/mqtt-bench/client.go | 4 ++-- tools/provision/provision.go | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/mqtt-bench/client.go b/tools/mqtt-bench/client.go index cb236a4b..9a0e0653 100644 --- a/tools/mqtt-bench/client.go +++ b/tools/mqtt-bench/client.go @@ -88,7 +88,7 @@ func (c *Client) publish(r chan *runResults) { for i := 0; i < c.MsgCount; i++ { wg.Add(1) - go func(mut *sync.Mutex, wg *sync.WaitGroup, t *[]*float64, i int, m message) { + go func(mut *sync.Mutex, wg *sync.WaitGroup, i int, m message) { defer wg.Done() m.Sent = time.Now() @@ -110,7 +110,7 @@ func (c *Client) publish(r chan *runResults) { if !c.Quiet && i > 0 && i%100 == 0 { log.Printf("Client %v published %v messages and keeps publishing...\n", c.ID, i) } - }(&mu, &wg, ×, i, m) + }(&mu, &wg, i, m) } wg.Wait() diff --git a/tools/provision/provision.go b/tools/provision/provision.go index 7520ce92..292538ac 100644 --- a/tools/provision/provision.go +++ b/tools/provision/provision.go @@ -140,7 +140,7 @@ func Provision(conf Config) { cid, err := s.CreateChannel(sdk.Channel{Name: fmt.Sprintf("%s-channel-%d", conf.Prefix, i)}, token) if err != nil { - log.Fatalf(err.Error()) + log.Fatalf("Failed to create the channel: %s", err.Error()) } channels[i] = &cid @@ -215,13 +215,18 @@ func Provision(conf Config) { fmt.Printf("# List of channels that things can publish to\n" + "# each channel is connected to each thing from things list\n") for i := 0; i < conf.Num; i++ { - for j := 0; j < conf.Num; j++ { + // Creating a new routine for each connect + // might be heavy on the network. + go func(wg *sync.WaitGroup, i int) { wg.Add(1) - go func(wg *sync.WaitGroup, i, j int) { - defer wg.Done() - s.ConnectThing(things[j].ID, *channels[i], token) - }(&wg, i, j) - } + defer wg.Done() + + for j := 0; j < conf.Num; j++ { + if err := s.ConnectThing(things[j].ID, *channels[i], token); err != nil { + log.Fatalf("Failed to connect thing %s to channel %s: %s", things[j].ID, *channels[i], err) + } + } + }(&wg, i) fmt.Printf("[[channels]]\nchannel_id = \"%s\"\n\n", *channels[i]) } wg.Wait()