Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8eae4f8

Browse files
authored
fix(coderd/provisionerdserver): fix test flake in TestHeartbeat (#11808)
1 parent979a920 commit8eae4f8

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
funcTestAcquireJob_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
funcTestAcquireJobWithCancel_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
defercancel()
@@ -101,8 +101,8 @@ func TestAcquireJobWithCancel_Cancel(t *testing.T) {
101101
funcTestHeartbeat(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(chanstruct{})
107107
heartbeatFn:=func(hbCtx context.Context)error {
108108
t.Logf("heartbeat")
@@ -114,28 +114,17 @@ func TestHeartbeat(t *testing.T) {
114114
returnnil
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-
deferfunc() {
132-
ifr:=recover();r!=nil {
133-
t.Fatalf("heartbeat received after cancel: %v",r)
134-
}
135-
}()
136-
137-
close(heartbeatChan)
138-
<-time.After(testutil.IntervalMedium)
124+
fori:=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
funcTestAcquireJob(t*testing.T) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp