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

Commit6de26a7

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

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

‎go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20240522100209-5cd2
77

88
require (
99
cdr.dev/slogv1.6.2-0.20240126064726-20367d4aede6
10-
github.com/benbjohnson/clockv1.3.5
1110
github.com/breml/rootcertsv0.2.11
1211
github.com/coder/coder/v2v2.10.1-0.20240528221537-02c36868b20b
12+
github.com/coder/quartzv0.1.0
1313
github.com/fatih/colorv1.17.0
1414
github.com/go-chi/chi/v5v5.1.0
1515
github.com/google/uuidv1.6.0
@@ -54,6 +54,7 @@ require (
5454
github.com/aws/aws-sdk-go-v2/service/stsv1.28.4// indirect
5555
github.com/aws/smithy-gov1.20.2// indirect
5656
github.com/aymanbagabas/go-osc52/v2v2.0.1// indirect
57+
github.com/benbjohnson/clockv1.3.5// indirect
5758
github.com/beorn7/perksv1.0.1// indirect
5859
github.com/cenkalti/backoff/v4v4.3.0// indirect
5960
github.com/cespare/xxhash/v2v2.2.0// indirect

‎go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ github.com/coder/coder/v2 v2.10.1-0.20240528221537-02c36868b20b h1:9cZlY9BnE0zYV
124124
github.com/coder/coder/v2v2.10.1-0.20240528221537-02c36868b20b/go.mod h1:o40ZZM8FESNC5hDp8/S92OSaPb/aV0jSySsh270z3Yc=
125125
github.com/coder/prettyv0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs=
126126
github.com/coder/prettyv0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc=
127+
github.com/coder/quartzv0.1.0 h1:cLL+0g5l7xTf6ordRnUMMiZtRE8Sq5LxpghS63vEXrQ=
128+
github.com/coder/quartzv0.1.0/go.mod h1:vsiCc+AHViMKH2CQpGIpFgdHIEQsxwm8yCscqKmzbRA=
127129
github.com/coder/retryv1.5.1 h1:iWu8YnD8YqHs3XwqrqsjoBTAVqT9ml6z9ViJ2wlMiqc=
128130
github.com/coder/retryv1.5.1/go.mod h1:blHMk9vs6LkoRT9ZHyuZo360cufXEhrxqvEzeMtRGoY=
129131
github.com/coder/serpentv0.7.0 h1:zGpD2GlF3lKIVkMjNGKbkip88qzd5r/TRcc30X/SrT0=

‎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"
@@ -21,6 +20,7 @@ import (
2120
"github.com/coder/coder/v2/agent/proto"
2221
"github.com/coder/coder/v2/codersdk"
2322
"github.com/coder/coder/v2/codersdk/agentsdk"
23+
"github.com/coder/quartz"
2424

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

3131
typepodEventLoggerOptionsstruct {
3232
client kubernetes.Interface
33-
clockclock.Clock
33+
clockquartz.Clock
3434
coderURL*url.URL
3535

3636
logger slog.Logger
@@ -50,7 +50,7 @@ func newPodEventLogger(ctx context.Context, opts podEventLoggerOptions) (*podEve
5050
opts.logDebounce=30*time.Second
5151
}
5252
ifopts.clock==nil {
53-
opts.clock=clock.New()
53+
opts.clock=quartz.NewReal()
5454
}
5555

5656
logCh:=make(chanagentLog,512)
@@ -389,7 +389,7 @@ type agentLog struct {
389389
typelogQueuerstruct {
390390
mu sync.Mutex
391391
logger slog.Logger
392-
clockclock.Clock
392+
clockquartz.Clock
393393
qchanagentLog
394394

395395
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