chore: refactor autobuild/notify to use clock test (#13566)

Refactor autobuild/notify and tests to use the clock testing library.

I also rewrote some of the comments because I didn't understand them when I was looking at the package.
This commit is contained in:
Spike Curtis
2024-06-13 16:01:17 +04:00
committed by GitHub
parent 4b0b9b08d5
commit 0268c7a659
3 changed files with 80 additions and 73 deletions
+2 -2
View File
@@ -711,12 +711,12 @@ func tryPollWorkspaceAutostop(ctx context.Context, client *codersdk.Client, work
lock := flock.New(filepath.Join(os.TempDir(), "coder-autostop-notify-"+workspace.ID.String()))
conditionCtx, cancelCondition := context.WithCancel(ctx)
condition := notifyCondition(conditionCtx, client, workspace.ID, lock)
stopFunc := notify.Notify(condition, workspacePollInterval, autostopNotifyCountdown...)
notifier := notify.New(condition, workspacePollInterval, autostopNotifyCountdown)
return func() {
// With many "ssh" processes running, `lock.TryLockContext` can be hanging until the context canceled.
// Without this cancellation, a CLI process with failed remote-forward could be hanging indefinitely.
cancelCondition()
stopFunc()
notifier.Close()
}
}