Skip to content

Commit

Permalink
Fix total time counting for PostRPCWithRetry
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Mar 30, 2022
1 parent 5d96081 commit 318ed49
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tests/utils/request_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 318ed49

Please sign in to comment.