mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -24,8 +24,8 @@ import (
|
||||
"tailscale.com/wgengine/wgcfg/nmcfg"
|
||||
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/coder/v2/tailnet/proto"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
const lostTimeout = 15 * time.Minute
|
||||
@@ -70,7 +70,7 @@ type configMaps struct {
|
||||
blockEndpoints bool
|
||||
|
||||
// for testing
|
||||
clock clock.Clock
|
||||
clock quartz.Clock
|
||||
}
|
||||
|
||||
func newConfigMaps(logger slog.Logger, engine engineConfigurable, nodeID tailcfg.NodeID, nodeKey key.NodePrivate, discoKey key.DiscoPublic) *configMaps {
|
||||
@@ -116,7 +116,7 @@ func newConfigMaps(logger slog.Logger, engine engineConfigurable, nodeID tailcfg
|
||||
}},
|
||||
},
|
||||
peers: make(map[uuid.UUID]*peerLifecycle),
|
||||
clock: clock.NewReal(),
|
||||
clock: quartz.NewReal(),
|
||||
}
|
||||
go c.configLoop()
|
||||
return c
|
||||
@@ -657,9 +657,9 @@ type peerLifecycle struct {
|
||||
node *tailcfg.Node
|
||||
lost bool
|
||||
lastHandshake time.Time
|
||||
lostTimer *clock.Timer
|
||||
lostTimer *quartz.Timer
|
||||
readyForHandshake bool
|
||||
readyForHandshakeTimer *clock.Timer
|
||||
readyForHandshakeTimer *quartz.Timer
|
||||
}
|
||||
|
||||
func (l *peerLifecycle) resetLostTimer() {
|
||||
|
||||
@@ -21,9 +21,9 @@ import (
|
||||
|
||||
"cdr.dev/slog"
|
||||
"cdr.dev/slog/sloggers/slogtest"
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/coder/v2/tailnet/proto"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
func TestConfigMaps_setAddresses_different(t *testing.T) {
|
||||
@@ -195,7 +195,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_neverConfigures(t *testing.
|
||||
discoKey := key.NewDisco()
|
||||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
|
||||
defer uut.close()
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
uut.clock = mClock
|
||||
|
||||
p1ID := uuid.UUID{1}
|
||||
@@ -239,7 +239,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_outOfOrder(t *testing.T) {
|
||||
discoKey := key.NewDisco()
|
||||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
|
||||
defer uut.close()
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
uut.clock = mClock
|
||||
|
||||
p1ID := uuid.UUID{1}
|
||||
@@ -310,7 +310,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake(t *testing.T) {
|
||||
discoKey := key.NewDisco()
|
||||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
|
||||
defer uut.close()
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
uut.clock = mClock
|
||||
|
||||
p1ID := uuid.UUID{1}
|
||||
@@ -381,7 +381,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_timeout(t *testing.T) {
|
||||
discoKey := key.NewDisco()
|
||||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
|
||||
defer uut.close()
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
uut.clock = mClock
|
||||
|
||||
p1ID := uuid.UUID{1}
|
||||
@@ -566,7 +566,7 @@ func TestConfigMaps_updatePeers_lost(t *testing.T) {
|
||||
discoKey := key.NewDisco()
|
||||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
|
||||
defer uut.close()
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
start := mClock.Now()
|
||||
uut.clock = mClock
|
||||
|
||||
@@ -651,7 +651,7 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) {
|
||||
discoKey := key.NewDisco()
|
||||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
|
||||
defer uut.close()
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
start := mClock.Now()
|
||||
uut.clock = mClock
|
||||
|
||||
@@ -736,7 +736,7 @@ func TestConfigMaps_setAllPeersLost(t *testing.T) {
|
||||
discoKey := key.NewDisco()
|
||||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
|
||||
defer uut.close()
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
start := mClock.Now()
|
||||
uut.clock = mClock
|
||||
|
||||
|
||||
+4
-4
@@ -17,8 +17,8 @@ import (
|
||||
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/v2/apiversion"
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/coder/v2/tailnet/proto"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
type streamIDContextKey struct{}
|
||||
@@ -240,7 +240,7 @@ func (c communicator) loopResp() {
|
||||
}
|
||||
|
||||
type NetworkTelemetryBatcher struct {
|
||||
clock clock.Clock
|
||||
clock quartz.Clock
|
||||
frequency time.Duration
|
||||
maxSize int
|
||||
batchFn func(batch []*proto.TelemetryEvent)
|
||||
@@ -248,11 +248,11 @@ type NetworkTelemetryBatcher struct {
|
||||
mu sync.Mutex
|
||||
closed chan struct{}
|
||||
done chan struct{}
|
||||
ticker *clock.Ticker
|
||||
ticker *quartz.Ticker
|
||||
pending []*proto.TelemetryEvent
|
||||
}
|
||||
|
||||
func NewNetworkTelemetryBatcher(clk clock.Clock, frequency time.Duration, maxSize int, batchFn func(batch []*proto.TelemetryEvent)) *NetworkTelemetryBatcher {
|
||||
func NewNetworkTelemetryBatcher(clk quartz.Clock, frequency time.Duration, maxSize int, batchFn func(batch []*proto.TelemetryEvent)) *NetworkTelemetryBatcher {
|
||||
b := &NetworkTelemetryBatcher{
|
||||
clock: clk,
|
||||
frequency: frequency,
|
||||
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
|
||||
"cdr.dev/slog"
|
||||
"cdr.dev/slog/sloggers/slogtest"
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/coder/v2/tailnet"
|
||||
"github.com/coder/coder/v2/tailnet/proto"
|
||||
"github.com/coder/coder/v2/tailnet/tailnettest"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
func TestClientService_ServeClient_V2(t *testing.T) {
|
||||
@@ -182,7 +182,7 @@ func TestNetworkTelemetryBatcher(t *testing.T) {
|
||||
|
||||
var (
|
||||
events = make(chan []*proto.TelemetryEvent, 64)
|
||||
mClock = clock.NewMock(t)
|
||||
mClock = quartz.NewMock(t)
|
||||
b = tailnet.NewNetworkTelemetryBatcher(mClock, time.Millisecond, 3, func(batch []*proto.TelemetryEvent) {
|
||||
assert.LessOrEqual(t, len(batch), 3)
|
||||
events <- batch
|
||||
|
||||
Reference in New Issue
Block a user