@@ -52,7 +52,8 @@ func TestWebhookRetryMaxThreeAttempts(t *testing.T) {
5252 }))
5353 defer srv .Close ()
5454
55- wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 })
55+ wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 },
56+ daemon .WithRetryBackoff (10 * time .Millisecond ))
5657 wc .Emit ("always-fail" , nil )
5758 wc .Close ()
5859
@@ -190,6 +191,7 @@ func TestWebhookDroppedCounterAccurate(t *testing.T) {
190191 t .Parallel ()
191192
192193 ready := make (chan struct {})
194+ var blockOnce sync.Once
193195 block := make (chan struct {})
194196
195197 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -203,17 +205,19 @@ func TestWebhookDroppedCounterAccurate(t *testing.T) {
203205 w .WriteHeader (200 )
204206 }))
205207 defer srv .Close ()
206- defer close (block )
208+ defer blockOnce . Do ( func () { close (block ) } )
207209
208- wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 })
210+ wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 },
211+ daemon .WithHTTPTimeout (200 * time .Millisecond ),
212+ daemon .WithRetryBackoff (10 * time .Millisecond ))
209213
210214 // Emit the first event to get the worker goroutine into the blocked HTTP request
211215 wc .Emit ("trigger" , nil )
212216
213217 // Wait until the worker is actually blocked in the server
214218 select {
215219 case <- ready :
216- case <- time .After (5 * time .Second ):
220+ case <- time .After (2 * time .Second ):
217221 t .Fatal ("timeout waiting for worker to start sending" )
218222 }
219223
@@ -228,6 +232,8 @@ func TestWebhookDroppedCounterAccurate(t *testing.T) {
228232 t .Fatal ("expected at least 1 dropped event when queue is overfull" )
229233 }
230234 t .Logf ("dropped %d events" , dropped )
235+
236+ blockOnce .Do (func () { close (block ) }) // unblock server so queued events drain with 200 OK
231237 wc .Close ()
232238}
233239
@@ -345,7 +351,8 @@ func TestWebhookRetryOn5xx(t *testing.T) {
345351 }))
346352 defer srv .Close ()
347353
348- wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 })
354+ wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 },
355+ daemon .WithRetryBackoff (10 * time .Millisecond ))
349356 wc .Emit ("retry.test" , nil )
350357 wc .Close ()
351358
@@ -494,15 +501,18 @@ func TestWebhookDroppedCounter(t *testing.T) {
494501 t .Parallel ()
495502
496503 // Create a server that blocks forever so the queue fills up
504+ var blockOnce sync.Once
497505 block := make (chan struct {})
498506 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
499507 <- block // block until test ends
500508 w .WriteHeader (200 )
501509 }))
502510 defer srv .Close ()
503- defer close (block )
511+ defer blockOnce . Do ( func () { close (block ) } )
504512
505- wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 })
513+ wc := daemon .NewWebhookClient (srv .URL , func () uint32 { return 1 },
514+ daemon .WithHTTPTimeout (200 * time .Millisecond ),
515+ daemon .WithRetryBackoff (10 * time .Millisecond ))
506516
507517 // Fill the 1024-item buffer. The first event will be consumed by the run
508518 // goroutine and block in post(), so we need 1024+1 more to fill the queue
@@ -520,5 +530,6 @@ func TestWebhookDroppedCounter(t *testing.T) {
520530 }
521531 t .Logf ("dropped %d events as expected" , dropped )
522532
533+ blockOnce .Do (func () { close (block ) }) // unblock server so queued events drain with 200 OK
523534 wc .Close ()
524535}
0 commit comments