Files
pulse/internal/dockeragent/deps.go
T
courtmanr@gmail.com 68e557e9f0 Fix Docker agent test JSON-marshal race by making the hook per-Agent
Same class of race fixed for newTimerFn in 8e5ef365d: tests swapped the
package-level jsonMarshalFn hook while async goroutines leaked from
earlier tests (sendCommandAck ack retries via runAsync) could still be
reading it, tripping the race detector. Replace the global with a
per-Agent jsonMarshalFn seam (nil defaults to json.Marshal), make the
decode payload helpers Agent methods so they use it, and inject the
failing marshaller into the tests that previously swapped the global.
Verified with go test ./internal/dockeragent/ -race -count=20.

Contract-Neutral: test seam refactor to fix data race, no public contract delta

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 17:16:06 +01:00

67 lines
2.0 KiB
Go

package dockeragent
import (
"context"
"crypto/rand"
"io"
"os"
"os/exec"
"runtime"
"syscall"
"time"
"github.com/moby/moby/client"
"github.com/rcourtman/pulse-go-rewrite/internal/hostmetrics"
)
var (
connectRuntimeFn = connectRuntime
hostmetricsCollect = hostmetrics.Collect
newTickerFn = time.NewTicker
randomDurationFn = randomDuration
nowFn = time.Now
sleepFn = time.Sleep
normalizeTargetsFn = normalizeTargets
buildRuntimeCandidatesFn = buildRuntimeCandidates
tryRuntimeCandidateFn = tryRuntimeCandidate
randIntFn = rand.Int
osExecutableFn = os.Executable
osCreateTempFn = os.CreateTemp
closeFileFn = func(f *os.File) error { return f.Close() }
osRenameFn = os.Rename
osChmodFn = os.Chmod
osRemoveFn = os.Remove
osReadFileFn = os.ReadFile
osWriteFileFn = os.WriteFile
osStatFn = os.Stat
syscallExecFn = syscall.Exec
goArch = runtime.GOARCH
unameMachine = func() (string, error) {
out, err := exec.Command("uname", "-m").Output()
if err != nil {
return "", err
}
return string(out), nil
}
machineIDPaths = []string{
"/etc/machine-id",
"/var/lib/dbus/machine-id",
}
unraidVersionPath = "/etc/unraid-version"
unraidPersistPath = "/boot/config/plugins/pulse-agent/pulse-agent"
unraidStartupScriptPath = "/boot/config/plugins/pulse-agent/start-pulse-agent.sh"
agentLogPath = "/var/log/pulse-agent.log"
openProcUptime = func() (io.ReadCloser, error) {
return os.Open("/proc/uptime")
}
newDockerClientFn = func(opts ...client.Opt) (dockerClient, error) {
return newMobyDockerClient(opts...)
}
selfUpdateFunc = func(a *Agent, ctx context.Context) error {
return a.selfUpdate(ctx)
}
execCommandContextFn = func(ctx context.Context, name string, arg ...string) *exec.Cmd {
return exec.CommandContext(ctx, name, arg...)
}
)