Skip to content

Commit fe02d07

Browse files
committed
Use quartz.Clock instead of time.AfterFunc in SetupACP
- Add Clock field to SetupACPConfig - Default to quartz.NewReal() if Clock is nil - Replace time.AfterFunc with config.Clock.AfterFunc for testability
1 parent 8a44a8f commit fe02d07

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/httpapi/setup.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
mf "github.com/coder/agentapi/lib/msgfmt"
1515
"github.com/coder/agentapi/lib/termexec"
1616
"github.com/coder/agentapi/x/acpio"
17+
"github.com/coder/quartz"
1718
)
1819

1920
type SetupProcessConfig struct {
@@ -64,6 +65,7 @@ func SetupProcess(ctx context.Context, config SetupProcessConfig) (*termexec.Pro
6465
type SetupACPConfig struct {
6566
Program string
6667
ProgramArgs []string
68+
Clock quartz.Clock
6769
}
6870

6971
// SetupACPResult contains the result of setting up an ACP process.
@@ -76,6 +78,10 @@ type SetupACPResult struct {
7678
func SetupACP(ctx context.Context, config SetupACPConfig) (*SetupACPResult, error) {
7779
logger := logctx.From(ctx)
7880

81+
if config.Clock == nil {
82+
config.Clock = quartz.NewReal()
83+
}
84+
7985
args := config.ProgramArgs
8086
logger.Info(fmt.Sprintf("Running (ACP): %s %s", config.Program, strings.Join(args, " ")))
8187

@@ -111,7 +117,7 @@ func SetupACP(ctx context.Context, config SetupACPConfig) (*SetupACPResult, erro
111117
_ = stdin.Close()
112118
_ = stdout.Close()
113119
// Force kill after timeout
114-
time.AfterFunc(5*time.Second, func() {
120+
config.Clock.AfterFunc(5*time.Second, func() {
115121
_ = cmd.Process.Kill()
116122
})
117123
case <-done:

0 commit comments

Comments
 (0)