From bd050c1d0335ca71cd5ea1aeacd6247262083da8 Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Thu, 12 Jul 2018 12:42:26 -0700 Subject: [PATCH] Make code smell better --- tools/tm-bench/main.go | 18 +++++------------- tools/tm-bench/transacter.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tools/tm-bench/main.go b/tools/tm-bench/main.go index 68b3bee16..f8a979fef 100644 --- a/tools/tm-bench/main.go +++ b/tools/tm-bench/main.go @@ -102,19 +102,6 @@ Examples: ) // Wait until transacters have begun until we get the start time - for { - started := true - for _, t := range transacters { - for i := 0; i < t.Connections; i++ { - if !t.connsStarted[i] && !t.connsBroken[i] { - started = false - } - } - } - if started { - break - } - } timeStart := time.Now() logger.Info("Time last transacter started", "t", timeStart) @@ -270,6 +257,11 @@ func startTransacters( transacters[i] = t } + // Wait until all transacters have started firing txs + for _, t := range transacters { + t.WaitUntilAllConnectionsStartedFiringTxs() + } + return transacters } diff --git a/tools/tm-bench/transacter.go b/tools/tm-bench/transacter.go index f89c55b7b..b11c174fa 100644 --- a/tools/tm-bench/transacter.go +++ b/tools/tm-bench/transacter.go @@ -86,6 +86,22 @@ func (t *transacter) Start() error { return nil } +// WaitUntilAllConnectionsStartedFiringTxs waits until all of this +// transacters connections have begun sending txs at the specified rate +func (t *transacter) WaitUntilAllConnectionsStartedFiringTxs() { + for { + started := true + for i := 0; i < t.Connections; i++ { + if !t.connsStarted[i] && !t.connsBroken[i] { + started = false + } + } + if started { + break + } + } +} + // Stop closes the connections. func (t *transacter) Stop() { t.stopped = true