(gcli *GrpcClient, query, want string, timeout time.Duration)
| 25 | ) |
| 26 | |
| 27 | func PollTillPassOrTimeout(gcli *GrpcClient, query, want string, timeout time.Duration) error { |
| 28 | timer := time.NewTimer(timeout) |
| 29 | |
| 30 | for { |
| 31 | resp, err := gcli.Query(query) |
| 32 | if err != nil { |
| 33 | return errors.Wrap(err, "error while query") |
| 34 | } |
| 35 | |
| 36 | err = CompareJSON(want, string(resp.Json)) |
| 37 | if err == nil { |
| 38 | return nil |
| 39 | } |
| 40 | select { |
| 41 | case <-timer.C: |
| 42 | return err |
| 43 | default: |
| 44 | time.Sleep(waitDurBeforeRetry) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // CompareJSON compares two JSON objects (passed as strings). |
| 50 | func CompareJSON(want, got string) error { |
searching dependent graphs…