Skip to content

Commit bcd1429

Browse files
committed
chore: get all tests passing
1 parent 792aa2d commit bcd1429

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

coderd/httpapi/httpapi_test.go

+40-6
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,47 @@ func TestServerSentEventSender(t *testing.T) {
549549
require.True(t, <-successC)
550550
})
551551

552-
t.Run("Cancels the entire connection if the request context cancels", func(t *testing.T) {
553-
t.FailNow()
554-
t.Parallel()
555-
})
556-
557552
t.Run("Sends a heartbeat to the client on a fixed internal of time to keep connections alive", func(t *testing.T) {
558-
t.FailNow()
559553
t.Parallel()
554+
555+
// Need add at least three heartbeats for something to be reliably
556+
// counted as an interval, but also need some wiggle room
557+
heartbeatCount := 3
558+
hbDuration := time.Duration(heartbeatCount) * httpapi.HeartbeatInterval
559+
timeout := hbDuration + (5 * time.Second)
560+
561+
ctx := testutil.Context(t, timeout)
562+
req := newBaseRequest(ctx)
563+
writer := newServerSentWriter(t)
564+
_, _, err := httpapi.ServerSentEventSender(writer, req)
565+
require.NoError(t, err)
566+
567+
type Result struct {
568+
Err error
569+
Success bool
570+
}
571+
resultC := make(chan Result)
572+
go func() {
573+
err := writer.
574+
clientConn.
575+
SetReadDeadline(time.Now().Add(timeout))
576+
if err != nil {
577+
resultC <- Result{err, false}
578+
return
579+
}
580+
for range heartbeatCount {
581+
pingBuffer := make([]byte, 1)
582+
pingSize, err := writer.clientConn.Read(pingBuffer)
583+
if err != nil || pingSize != 1 {
584+
resultC <- Result{err, false}
585+
return
586+
}
587+
}
588+
resultC <- Result{nil, true}
589+
}()
590+
591+
result := <-resultC
592+
require.NoError(t, result.Err)
593+
require.True(t, result.Success)
560594
})
561595
}

0 commit comments

Comments
 (0)