chore: spin clock library out to coder/quartz repo (#13777)

Code that was in `/clock` has been moved to github.com/coder/quartz.  This PR refactors our use of the clock library to point to the external Quartz repo.
This commit is contained in:
Spike Curtis
2024-07-03 15:02:54 +04:00
committed by GitHub
parent a110d18275
commit e5268e4551
25 changed files with 61 additions and 1986 deletions
+4 -4
View File
@@ -8,7 +8,7 @@ import (
"time"
"cdr.dev/slog"
"github.com/coder/coder/v2/clock"
"github.com/coder/quartz"
)
const (
@@ -31,15 +31,15 @@ type Watchdog struct {
timeout chan struct{}
// for testing
clock clock.Clock
clock quartz.Clock
}
func NewWatchdog(ctx context.Context, logger slog.Logger, ps Pubsub) *Watchdog {
return NewWatchdogWithClock(ctx, logger, ps, clock.NewReal())
return NewWatchdogWithClock(ctx, logger, ps, quartz.NewReal())
}
// NewWatchdogWithClock returns a watchdog with the given clock. Product code should always call NewWatchDog.
func NewWatchdogWithClock(ctx context.Context, logger slog.Logger, ps Pubsub, c clock.Clock) *Watchdog {
func NewWatchdogWithClock(ctx context.Context, logger slog.Logger, ps Pubsub, c quartz.Clock) *Watchdog {
ctx, cancel := context.WithCancel(ctx)
w := &Watchdog{
ctx: ctx,
+3 -3
View File
@@ -8,15 +8,15 @@ import (
"cdr.dev/slog"
"cdr.dev/slog/sloggers/slogtest"
"github.com/coder/coder/v2/clock"
"github.com/coder/coder/v2/coderd/database/pubsub"
"github.com/coder/coder/v2/testutil"
"github.com/coder/quartz"
)
func TestWatchdog_NoTimeout(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
mClock := clock.NewMock(t)
mClock := quartz.NewMock(t)
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
fPS := newFakePubsub()
@@ -74,7 +74,7 @@ func TestWatchdog_NoTimeout(t *testing.T) {
func TestWatchdog_Timeout(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
mClock := clock.NewMock(t)
mClock := quartz.NewMock(t)
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
fPS := newFakePubsub()