Skip to content

Commit d5e162f

Browse files
authored
Scope down time sensitive code. (#138)
The intention is to reduce flakes in this test. The test now will block until the 50,000 expected records are processed. Then it will wait for a second for potential extra records; because none are expected, there should be on flakes when the code is operating correctly.
1 parent 1df8b4e commit d5e162f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tail/tail_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ func TestTailFuzz(t *testing.T) {
6565
}
6666
written = append(written, rec)
6767
}
68-
time.Sleep(time.Second)
69-
cancel()
7068
}()
7169

7270
wr := wal.NewReader(rc)
7371

74-
for wr.Next() {
72+
// Expect `count` records; read them all, if possible. The test will
73+
// time out if fewer records show up.
74+
for len(read) < count && wr.Next() {
7575
read = append(read, append([]byte(nil), wr.Record()...))
7676
}
7777
if wr.Err() != nil {
@@ -85,6 +85,22 @@ func TestTailFuzz(t *testing.T) {
8585
t.Fatalf("record %d doesn't match", i)
8686
}
8787
}
88+
// Attempt to read one more record, but expect no more records.
89+
// Give the reader a chance to run for a while, then cancel its
90+
// context so the test doesn't time out.
91+
go func() {
92+
time.Sleep(time.Second)
93+
cancel()
94+
}()
95+
// It's safe to call Next() again. The last invocation must have returned `true`,
96+
// or else the comparison between `read` and `written` above will fail and cause
97+
// the test to end early.
98+
if wr.Next() {
99+
t.Fatal("read unexpected record")
100+
}
101+
if wr.Err() != nil {
102+
t.Fatal(wr.Err())
103+
}
88104
}
89105

90106
func BenchmarkTailFuzz(t *testing.B) {

0 commit comments

Comments
 (0)