Skip to content

Commit 0a0506a

Browse files
committed
tests: Slow down generator tests to work around race condition
5ms resolution is too fine for reliable tests. Increase delays by a factor of 10 to improve the chances that the desired path will win the race. Ideally the test would be rewritten to remove the races entirely, but I'll leave that as a future exercise.
1 parent 4d61feb commit 0a0506a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

internal/generator/generator_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestGenerateFromEvents(t *testing.T) {
4141
for rsc.Scan() {
4242
w.Write([]byte(rsc.Text()))
4343
w.(http.Flusher).Flush()
44-
time.Sleep(15 * time.Millisecond)
44+
time.Sleep(150 * time.Millisecond)
4545
}
4646
time.Sleep(500 * time.Millisecond)
4747
}))
@@ -168,13 +168,13 @@ func TestGenerateFromEvents(t *testing.T) {
168168
Template: tmplFile.Name(),
169169
Dest: destFiles[2].Name(),
170170
Watch: true,
171-
Wait: &config.Wait{Min: 20 * time.Millisecond, Max: 25 * time.Millisecond},
171+
Wait: &config.Wait{Min: 200 * time.Millisecond, Max: 250 * time.Millisecond},
172172
},
173173
{
174174
Template: tmplFile.Name(),
175175
Dest: destFiles[3].Name(),
176176
Watch: true,
177-
Wait: &config.Wait{Min: 25 * time.Millisecond, Max: 100 * time.Millisecond},
177+
Wait: &config.Wait{Min: 250 * time.Millisecond, Max: 1 * time.Second},
178178
},
179179
},
180180
},
@@ -191,12 +191,12 @@ func TestGenerateFromEvents(t *testing.T) {
191191

192192
// The counter is incremented in each output file in the following sequence:
193193
//
194-
// init 0ms 5ms 10ms 15ms 20ms 25ms 30ms 35ms 40ms 45ms 50ms 55ms
194+
// init 150ms 200ms 250ms 300ms 350ms 400ms 450ms 500ms 550ms 600ms 650ms 700ms
195195
// ├──────╫──────┼──────┼──────╫──────┼──────┼──────╫──────┼──────┼──────┼──────┼──────┤
196196
// File0 ├─ 1 ║ ║ ║
197197
// File1 ├─ 1 ╟─ 2 ╟─ 3 ╟─ 5
198-
// File2 ├─ 1 ╟───── max (25ms) ──║───────────> 4 ╟─────── min (20ms) ──────> 6
199-
// File3 └─ 1 ╟──────────────────> ╟──────────────────> ╟─────────── min (25ms) ─────────> 7
198+
// File2 ├─ 1 ╟───── max (250ms) ──║───────────> 4 ╟─────── min (200ms) ─────> 6
199+
// File3 └─ 1 ╟──────────────────> ╟──────────────────> ╟─────────── min (250ms) ────────> 7
200200
// ┌───╨───┐ ┌───╨──┐ ┌───╨───┐
201201
// │ start │ │ stop │ │ start │
202202
// └───────┘ └──────┘ └───────┘

0 commit comments

Comments
 (0)