From 5865050f015e4ec5a1541897c287f34cfd16f739 Mon Sep 17 00:00:00 2001 From: ocnc <97242826+oofncubed@users.noreply.github.com> Date: Fri, 19 May 2023 06:28:49 -0400 Subject: [PATCH] fix(tests): Fixes LatestHeight in testutil network (#16219) Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> --- testutil/network/network.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index f1616e5953..ae6eaf454c 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -677,9 +677,21 @@ func (n *Network) LatestHeight() (int64, error) { case <-timeout.C: return latestHeight, errors.New("timeout exceeded waiting for block") case <-ticker.C: - res, err := queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{}) - if err == nil && res != nil { - return res.SdkBlock.Header.Height, nil + done := make(chan struct{}) + go func() { + res, err := queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{}) + if err == nil && res != nil { + latestHeight = res.SdkBlock.Header.Height + } + done <- struct{}{} + }() + select { + case <-timeout.C: + return latestHeight, errors.New("timeout exceeded waiting for block") + case <-done: + if latestHeight != 0 { + return latestHeight, nil + } } } }