Skip to content

Commit 8eae4f8

Browse files
authored
fix(coderd/provisionerdserver): fix test flake in TestHeartbeat (#11808)
1 parent 979a920 commit 8eae4f8

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

coderd/provisionerdserver/provisionerdserver_test.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func testUserQuietHoursScheduleStore() *atomic.Pointer[schedule.UserQuietHoursSc
6767

6868
func TestAcquireJob_LongPoll(t *testing.T) {
6969
t.Parallel()
70-
//nolint:dogsled // ૮・ᴥ・ა
70+
//nolint:dogsled
7171
srv, _, _, _ := setup(t, false, &overrides{acquireJobLongPollDuration: time.Microsecond})
7272
job, err := srv.AcquireJob(context.Background(), nil)
7373
require.NoError(t, err)
@@ -76,7 +76,7 @@ func TestAcquireJob_LongPoll(t *testing.T) {
7676

7777
func TestAcquireJobWithCancel_Cancel(t *testing.T) {
7878
t.Parallel()
79-
//nolint:dogsled // ૮ ˶′ﻌ ‵˶ ა
79+
//nolint:dogsled
8080
srv, _, _, _ := setup(t, false, nil)
8181
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
8282
defer cancel()
@@ -101,8 +101,8 @@ func TestAcquireJobWithCancel_Cancel(t *testing.T) {
101101
func TestHeartbeat(t *testing.T) {
102102
t.Parallel()
103103

104-
ctx, cancel := context.WithCancel(context.Background())
105-
t.Cleanup(cancel)
104+
numBeats := 3
105+
ctx := testutil.Context(t, testutil.WaitShort)
106106
heartbeatChan := make(chan struct{})
107107
heartbeatFn := func(hbCtx context.Context) error {
108108
t.Logf("heartbeat")
@@ -114,28 +114,17 @@ func TestHeartbeat(t *testing.T) {
114114
return nil
115115
}
116116
}
117-
//nolint:dogsled // 。:゚૮ ˶ˆ ﻌ ˆ˶ ა ゚:。
117+
//nolint:dogsled
118118
_, _, _, _ = setup(t, false, &overrides{
119119
ctx: ctx,
120120
heartbeatFn: heartbeatFn,
121121
heartbeatInterval: testutil.IntervalFast,
122122
})
123123

124-
_, ok := <-heartbeatChan
125-
require.True(t, ok, "first heartbeat not received")
126-
_, ok = <-heartbeatChan
127-
require.True(t, ok, "second heartbeat not received")
128-
cancel()
129-
// Close the channel to ensure we don't receive any more heartbeats.
130-
// The test will fail if we do.
131-
defer func() {
132-
if r := recover(); r != nil {
133-
t.Fatalf("heartbeat received after cancel: %v", r)
134-
}
135-
}()
136-
137-
close(heartbeatChan)
138-
<-time.After(testutil.IntervalMedium)
124+
for i := 0; i < numBeats; i++ {
125+
testutil.RequireRecvCtx(ctx, t, heartbeatChan)
126+
}
127+
// goleak.VerifyTestMain ensures that the heartbeat goroutine does not leak
139128
}
140129

141130
func TestAcquireJob(t *testing.T) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy