Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/apphealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"golang.org/x/xerrors"

"cdr.dev/slog"
"github.com/coder/coder/v2/clock"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/quartz"
)

// PostWorkspaceAgentAppHealth updates the workspace app health.
Expand All @@ -23,7 +23,7 @@ type WorkspaceAppHealthReporter func(ctx context.Context)

// NewWorkspaceAppHealthReporter creates a WorkspaceAppHealthReporter that reports app health to coderd.
func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.WorkspaceApp, postWorkspaceAgentAppHealth PostWorkspaceAgentAppHealth) WorkspaceAppHealthReporter {
return NewAppHealthReporterWithClock(logger, apps, postWorkspaceAgentAppHealth, clock.NewReal())
return NewAppHealthReporterWithClock(logger, apps, postWorkspaceAgentAppHealth, quartz.NewReal())
}

// NewAppHealthReporterWithClock is only called directly by test code. Product code should call
Expand All @@ -32,7 +32,7 @@ func NewAppHealthReporterWithClock(
logger slog.Logger,
apps []codersdk.WorkspaceApp,
postWorkspaceAgentAppHealth PostWorkspaceAgentAppHealth,
clk clock.Clock,
clk quartz.Clock,
) WorkspaceAppHealthReporter {
logger = logger.Named("apphealth")

Expand Down
10 changes: 5 additions & 5 deletions agent/apphealth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/coder/coder/v2/agent"
"github.com/coder/coder/v2/agent/agenttest"
"github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/clock"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/testutil"
"github.com/coder/quartz"
)

func TestAppHealth_Healthy(t *testing.T) {
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestAppHealth_Healthy(t *testing.T) {
httpapi.Write(r.Context(), w, http.StatusOK, nil)
}),
}
mClock := clock.NewMock(t)
mClock := quartz.NewMock(t)
healthcheckTrap := mClock.Trap().TickerFunc("healthcheck")
defer healthcheckTrap.Close()
reportTrap := mClock.Trap().TickerFunc("report")
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestAppHealth_500(t *testing.T) {
}),
}

mClock := clock.NewMock(t)
mClock := quartz.NewMock(t)
healthcheckTrap := mClock.Trap().TickerFunc("healthcheck")
defer healthcheckTrap.Close()
reportTrap := mClock.Trap().TickerFunc("report")
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestAppHealth_Timeout(t *testing.T) {
<-r.Context().Done()
}),
}
mClock := clock.NewMock(t)
mClock := quartz.NewMock(t)
start := mClock.Now()

// for this test, it's easier to think in the number of milliseconds elapsed
Expand Down Expand Up @@ -235,7 +235,7 @@ func setupAppReporter(
ctx context.Context, t *testing.T,
apps []codersdk.WorkspaceApp,
handlers []http.Handler,
clk clock.Clock,
clk quartz.Clock,
) (*agenttest.FakeAgentAPI, func()) {
closers := []func(){}
for _, app := range apps {
Expand Down
Loading
Loading