Skip to content

Commit bf26e9a

Browse files
authored
fix: fix flaky TestAsyncTransport_FlushWithContext (#1222)
1 parent d1edaf4 commit bf26e9a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

internal/http/transport_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ func TestAsyncTransport_FlushWithContext(t *testing.T) {
302302
})
303303

304304
t.Run("timeout", func(t *testing.T) {
305+
blockChan := make(chan struct{})
305306
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
307+
<-blockChan
306308
w.WriteHeader(http.StatusOK)
307309
}))
308310
defer server.Close()
@@ -314,11 +316,15 @@ func TestAsyncTransport_FlushWithContext(t *testing.T) {
314316
if !ok {
315317
t.Fatalf("expected *AsyncTransport, got %T", tr)
316318
}
317-
defer transport.Close()
319+
defer func() {
320+
close(blockChan)
321+
transport.Close()
322+
}()
323+
324+
_ = transport.SendEnvelope(testEnvelope(protocol.EnvelopeItemTypeEvent))
318325

319-
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond)
326+
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
320327
defer cancel()
321-
time.Sleep(10 * time.Millisecond)
322328

323329
if transport.FlushWithContext(ctx) {
324330
t.Error("FlushWithContext should timeout")

0 commit comments

Comments
 (0)