Skip to content

Commit 864e225

Browse files
go/client: make test more resilient (google#1361)
Only fail the retry timing test if the difference in timings is both: - more than 100ms out - more than 10% out. Hopefully this will reduce test flakes.
1 parent c8a4e29 commit 864e225

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

go/client/logclient_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ func TestAddChainRetries(t *testing.T) {
226226
if err != nil {
227227
t.Fatalf("Failed to create client: %v", err)
228228
}
229-
leeway := time.Millisecond * 100
230-
instant := time.Millisecond
231-
fiveSeconds := time.Second * 5
232-
sevenSeconds := time.Second * 7 // = 1 + 2 + 4
229+
const leeway = time.Millisecond * 100
230+
const leewayRatio = 0.1 // 10%
231+
const instant = time.Millisecond
232+
const fiveSeconds = time.Second * 5
233+
const sevenSeconds = time.Second * 7 // = 1 + 2 + 4
233234

234235
tests := []struct {
235236
deadlineLength int
@@ -258,7 +259,9 @@ func TestAddChainRetries(t *testing.T) {
258259
started := time.Now()
259260
sct, err := client.AddChain(deadline, chain)
260261
took := time.Since(started)
261-
if math.Abs(float64(took-test.expected)) > float64(leeway) {
262+
delta := math.Abs(float64(took - test.expected))
263+
ratio := delta / float64(test.expected)
264+
if delta > float64(leeway) && ratio > leewayRatio {
262265
t.Errorf("#%d Submission took an unexpected length of time: %s, expected ~%s", i, took, test.expected)
263266
}
264267
if test.success && err != nil {

0 commit comments

Comments
 (0)