From f2a83a07f9fa23ac66f2ae43eeb6ee5182b04afd Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Mon, 25 Jun 2018 14:53:48 -0700 Subject: [PATCH] Merge PR #1366: tests: add method to wait for n blocks to pass Adds a helper method to tests/util.go for waiting for N blocks to pass. This is useful for situations when you need to wait for multiple blocks to pass, but don't know the current block number. In general, this is safer than using "wait for height", since the block height could have advanced further than expected while the test was running. Resolves remaining point in #1283 --- CHANGELOG.md | 1 + tests/util.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f1ef031e4..789361078b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ FEATURES * [tools] Switch gometalinter to the stable version * [tools] Add checking for misspellings and for incorrectly formatted files in circle CI * [server] Default config now creates a profiler at port 6060, and increase p2p send/recv rates +* [tests] Add WaitForNextNBlocksTM helper method FIXES * \#1259 - fix bug where certain tests that could have a nil pointer in defer diff --git a/tests/util.go b/tests/util.go index 9e2c0d0446..cc95f1e241 100644 --- a/tests/util.go +++ b/tests/util.go @@ -15,13 +15,19 @@ import ( // Wait for the next tendermint block from the Tendermint RPC // on localhost func WaitForNextHeightTM(port string) { + WaitForNextNBlocksTM(1, port) +} + +// Wait for N tendermint blocks to pass using the Tendermint RPC +// on localhost +func WaitForNextNBlocksTM(n int64, port string) { url := fmt.Sprintf("http://localhost:%v", port) cl := tmclient.NewHTTP(url, "/websocket") resBlock, err := cl.Block(nil) if err != nil { panic(err) } - waitForHeightTM(resBlock.Block.Height+1, url) + waitForHeightTM(resBlock.Block.Height+n, url) } // Wait for the given height from the Tendermint RPC