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

Commit79b0702

Browse files
committed
feat: switch to quartz for time testing
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent24d4ce5 commit79b0702

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

‎go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20240702054557-aa55
99

1010
require (
1111
cdr.dev/slogv1.6.2-0.20240126064726-20367d4aede6
12-
github.com/benbjohnson/clockv1.3.5
1312
github.com/breml/rootcertsv0.2.11
1413
github.com/coder/coder/v2v2.10.1-0.20240703121105-f6639b788f7b
14+
github.com/coder/quartzv0.1.0
1515
github.com/fatih/colorv1.17.0
1616
github.com/go-chi/chi/v5v5.1.0
1717
github.com/google/uuidv1.6.0
@@ -61,7 +61,6 @@ require (
6161
github.com/cespare/xxhash/v2v2.2.0// indirect
6262
github.com/charmbracelet/lipglossv0.8.0// indirect
6363
github.com/coder/prettyv0.0.0-20230908205945-e89ba86370e0// indirect
64-
github.com/coder/quartzv0.1.0// indirect
6564
github.com/coder/retryv1.5.1// indirect
6665
github.com/coder/serpentv0.7.0// indirect
6766
github.com/coder/terraform-provider-coderv0.23.0// indirect

‎go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
9797
github.com/aymanbagabas/go-osc52/v2v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
9898
github.com/aymerick/douceurv0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
9999
github.com/aymerick/douceurv0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
100-
github.com/benbjohnson/clockv1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
101-
github.com/benbjohnson/clockv1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
102100
github.com/beorn7/perksv1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
103101
github.com/beorn7/perksv1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
104102
github.com/bool64/sharedv0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=

‎logger.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/benbjohnson/clock"
1110
"github.com/fatih/color"
1211
"github.com/google/uuid"
1312
appsv1"k8s.io/api/apps/v1"
@@ -20,6 +19,7 @@ import (
2019
"cdr.dev/slog"
2120
"github.com/coder/coder/v2/codersdk"
2221
"github.com/coder/coder/v2/codersdk/agentsdk"
22+
"github.com/coder/quartz"
2323

2424
// *Never* remove this. Certificates are not bundled as part
2525
// of the container, so this is necessary for all connections
@@ -29,7 +29,7 @@ import (
2929

3030
typepodEventLoggerOptionsstruct {
3131
client kubernetes.Interface
32-
clockclock.Clock
32+
clockquartz.Clock
3333
coderURL*url.URL
3434

3535
logger slog.Logger
@@ -49,7 +49,7 @@ func newPodEventLogger(ctx context.Context, opts podEventLoggerOptions) (*podEve
4949
opts.logDebounce=30*time.Second
5050
}
5151
ifopts.clock==nil {
52-
opts.clock=clock.New()
52+
opts.clock=quartz.NewReal()
5353
}
5454

5555
logCh:=make(chanagentLog,512)
@@ -388,7 +388,7 @@ type agentLog struct {
388388
typelogQueuerstruct {
389389
mu sync.Mutex
390390
logger slog.Logger
391-
clockclock.Clock
391+
clockquartz.Clock
392392
qchanagentLog
393393

394394
coderURL*url.URL
@@ -525,7 +525,7 @@ func (l *logQueuer) loggerTimeout(agentToken string) {
525525
typeagentLoggerLifecyclestruct {
526526
scriptLogger agentsdk.ScriptLogger
527527

528-
closeTimer*clock.Timer
528+
closeTimer*quartz.Timer
529529
closefunc()
530530
}
531531

‎logger_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/benbjohnson/clock"
1514
"github.com/go-chi/chi/v5"
1615
"github.com/hashicorp/yamux"
1716
"github.com/stretchr/testify/require"
@@ -30,6 +29,7 @@ import (
3029
"github.com/coder/coder/v2/codersdk"
3130
"github.com/coder/coder/v2/codersdk/agentsdk"
3231
"github.com/coder/coder/v2/testutil"
32+
"github.com/coder/quartz"
3333
)
3434

3535
funcTestReplicaSetEvents(t*testing.T) {
@@ -43,7 +43,7 @@ func TestReplicaSetEvents(t *testing.T) {
4343
namespace:="test-namespace"
4444
client:=fake.NewSimpleClientset()
4545

46-
cMock:=clock.NewMock()
46+
cMock:=quartz.NewMock(t)
4747
reporter,err:=newPodEventLogger(ctx,podEventLoggerOptions{
4848
client:client,
4949
coderURL:agentURL,
@@ -140,7 +140,7 @@ func TestPodEvents(t *testing.T) {
140140
namespace:="test-namespace"
141141
client:=fake.NewSimpleClientset()
142142

143-
cMock:=clock.NewMock()
143+
cMock:=quartz.NewMock(t)
144144
reporter,err:=newPodEventLogger(ctx,podEventLoggerOptions{
145145
client:client,
146146
coderURL:agentURL,
@@ -284,7 +284,7 @@ func Test_logQueuer(t *testing.T) {
284284
api:=newFakeAgentAPI(t)
285285
agentURL,err:=url.Parse(api.server.URL)
286286
require.NoError(t,err)
287-
clock:=clock.NewMock()
287+
clock:=quartz.NewMock(t)
288288
ttl:=time.Second
289289

290290
ch:=make(chanagentLog)
@@ -300,7 +300,7 @@ func Test_logQueuer(t *testing.T) {
300300
},
301301
}
302302

303-
ctx,cancel:=context.WithCancel(context.Background())
303+
ctx,cancel:=context.WithTimeout(context.Background(),10*time.Second)
304304
defercancel()
305305
golq.work(ctx)
306306

@@ -335,7 +335,7 @@ func Test_logQueuer(t *testing.T) {
335335
logs=testutil.RequireRecvCtx(ctx,t,api.logs)
336336
require.Len(t,logs,1)
337337

338-
clock.Add(2*ttl)
338+
clock.Advance(ttl)
339339
// wait for the client to disconnect
340340
_=testutil.RequireRecvCtx(ctx,t,api.disconnect)
341341
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp