Skip to content

fix: race in TestProcessCommandAgentConnected + 6 lint issues#259

Merged
JoshuaAFerguson merged 1 commit into
mainfrom
fix/lint-and-second-race
Apr 25, 2026
Merged

fix: race in TestProcessCommandAgentConnected + 6 lint issues#259
JoshuaAFerguson merged 1 commit into
mainfrom
fix/lint-and-second-race

Conversation

@JoshuaAFerguson

Copy link
Copy Markdown
Member

Summary

Two pre-existing CI failures newly visible after PR #255 / #256 made the lint and test infrastructure functional:

1. Second sqlmock race

`TestProcessCommandAgentConnected` raced on go-sqlmock for the same reason `TestUpdateAgentHeartbeat` did (PR #256) — `go hub.Run()` goroutine inside `sqlmock.exec` while the test goroutine calls `mock.ExpectExec`. Apply the same `ExpectationsWereMet` polling pattern.

2. golangci-lint v2.5 findings (newly running)

File Issue Fix
`agent_vnc_tunnel.go:179` unchecked `tunnel.conn.Close()` `_ = tunnel.conn.Close()`
`main.go:238` unchecked `a.wsConn.Close()` `_ = a.wsConn.Close()`
`main.go:536` unchecked deferred `resp.Body.Close()` `defer func() { _ = ... }()`
`main.go:583,587` unchecked `retryResp.Body.Close()` (×2) `_ = retryResp.Body.Close()`
`internal/errors/errors.go:28` ST1005 capitalized "Kubernetes resource not found" lowercase to "kubernetes…"

Verified

  • `go test -race -run TestProcessCommandAgentConnected -count=10 ./internal/services/` clean (10/10)
  • `go build ./...` clean in both modules

Deferred

Other test files (`agent_hub_redis_test.go`, `websocket_enterprise_test.go`, …) use the same `time.Sleep` + `mock.ExpectExec` pattern. They have not yet failed under `-race` in CI; defer until they do (or a sweep PR if there's appetite).

Two pre-existing CI failures newly visible after PR #255 / #256 made
the lint and test infrastructure functional:

1. TestProcessCommandAgentConnected raced on go-sqlmock for the same
   reason as TestUpdateAgentHeartbeat (PR #256). Apply the same
   ExpectationsWereMet polling pattern.

2. golangci-lint v2.5 (newly running) found 5 unchecked Close() return
   values in k8s-agent (vnc tunnel, websocket conn, two HTTP retry
   bodies) plus one staticcheck ST1005 capitalized error string.

Verified: 10 race reruns clean, both modules build clean.

Other test files (agent_hub_redis_test.go, websocket_enterprise_test.go,
etc) use the same time.Sleep + mock.ExpectExec pattern. Deferred to a
follow-up — they have not yet failed in CI under -race.
@JoshuaAFerguson JoshuaAFerguson merged commit 5d8c6d8 into main Apr 25, 2026
16 of 28 checks passed
@JoshuaAFerguson JoshuaAFerguson deleted the fix/lint-and-second-race branch April 25, 2026 18:21
@github-actions github-actions Bot added testing component:backend Backend API (Go) component:k8s-agent Kubernetes Agent labels Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant