From 318ed495fc0aeadfe7e17d1b65ffc02ca962f2fb Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Wed, 30 Mar 2022 09:46:19 +0000 Subject: [PATCH] Fix total time counting for `PostRPCWithRetry` --- tests/utils/request_utils.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/utils/request_utils.go b/tests/utils/request_utils.go index ea6c1c4ba9..eff8b8c52a 100644 --- a/tests/utils/request_utils.go +++ b/tests/utils/request_utils.go @@ -68,22 +68,26 @@ func PostRPCWithRetry(ctx context.Context, endpoint, method, params string, data, err := PostRPC(postRPCCtx, endpoint, method, params) - postRPCCancel() if err == nil { + postRPCCancel() return data, nil } - if ctx.Err() == nil { - continue - } + // wait for full requestWait duration or main context cancelation + <-postRPCCtx.Done() + postRPCCancel() - totalTime := time.Duration(try) * requestWait - tryWord := "try" - if try > 1 { - tryWord = "tries" + if ctx.Err() != nil { + break } - return nil, fmt.Errorf("after %d %s totalling %s: %w", try, tryWord, totalTime, err) } + + totalTime := time.Duration(try) * requestWait + tryWord := "try" + if try > 1 { + tryWord = "tries" + } + return nil, fmt.Errorf("after %d %s totalling %s: %w", try, tryWord, totalTime, err) } // DecodeRPC will decode []body into target interface