Skip to content

Commit c8cfb0b

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 40e53d2 commit c8cfb0b

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
@@ -39,7 +39,7 @@ func TestGenerateFromEvents(t *testing.T) {
3939
for rsc.Scan() {
4040
w.Write([]byte(rsc.Text()))
4141
w.(http.Flusher).Flush()
42-
time.Sleep(15 * time.Millisecond)
42+
time.Sleep(150 * time.Millisecond)
4343
}
4444
time.Sleep(500 * time.Millisecond)
4545
}))
@@ -166,13 +166,13 @@ func TestGenerateFromEvents(t *testing.T) {
166166
Template: tmplFile.Name(),
167167
Dest: destFiles[2].Name(),
168168
Watch: true,
169-
Wait: &config.Wait{Min: 20 * time.Millisecond, Max: 25 * time.Millisecond},
169+
Wait: &config.Wait{Min: 200 * time.Millisecond, Max: 250 * time.Millisecond},
170170
},
171171
{
172172
Template: tmplFile.Name(),
173173
Dest: destFiles[3].Name(),
174174
Watch: true,
175-
Wait: &config.Wait{Min: 25 * time.Millisecond, Max: 100 * time.Millisecond},
175+
Wait: &config.Wait{Min: 250 * time.Millisecond, Max: 1 * time.Second},
176176
},
177177
},
178178
},
@@ -189,12 +189,12 @@ func TestGenerateFromEvents(t *testing.T) {
189189

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

0 commit comments

Comments
 (0)