Skip to content

Commit f422504

Browse files
committed
chore: add last major test
1 parent 28381fd commit f422504

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

coderd/httpapi/httpapi_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ func TestOneWayWebSocket(t *testing.T) {
392392
t.Run("Sends a heartbeat to the socket on a fixed internal of time to keep connections alive", func(t *testing.T) {
393393
t.Parallel()
394394

395-
timeout := httpapi.HeartbeatInterval + (5 * time.Second)
395+
// Need add at least three heartbeats for something to be reliably
396+
// counted as an interval, but also need some wiggle room
397+
heartbeatCount := 3
398+
hbDuration := time.Duration(heartbeatCount) * httpapi.HeartbeatInterval
399+
timeout := hbDuration + (5 * time.Second)
400+
396401
ctx := testutil.Context(t, timeout)
397402
req := newBaseRequest(ctx)
398403
writer := newWebsocketWriter()
@@ -408,14 +413,20 @@ func TestOneWayWebSocket(t *testing.T) {
408413
go func() {
409414
err := writer.
410415
clientConn.
411-
SetReadDeadline(time.Now().Add(httpapi.HeartbeatInterval))
416+
SetReadDeadline(time.Now().Add(hbDuration))
412417
if err != nil {
413418
resultC <- Result{err, false}
414419
return
415420
}
416-
pingBuffer := make([]byte, 1)
417-
pingSize, err := writer.clientConn.Read(pingBuffer)
418-
resultC <- Result{err, pingSize == 1}
421+
for range heartbeatCount {
422+
pingBuffer := make([]byte, 1)
423+
pingSize, err := writer.clientConn.Read(pingBuffer)
424+
if err != nil || pingSize != 1 {
425+
resultC <- Result{err, false}
426+
return
427+
}
428+
}
429+
resultC <- Result{nil, true}
419430
}()
420431

421432
result := <-resultC

0 commit comments

Comments
 (0)