test: consolidate resp write-error cases, honor lock preconditions

Review fixes (Task 8, second pass):

- Fold TestRESPClient_AttemptPipelineLocked_WriteError and
  TestRESPClient_HandshakeLocked_WriteError into one table,
  TestRESPClient_WriteError_BrokenPipe — both exercised the identical
  broken-pipe shape on a pre-set fakeConn.
- Take c.mu.Lock()/Unlock() around every direct call to an internal
  "*Locked" method (ensureConnLocked, attemptPipelineLocked x2,
  handshakeLocked) per each method's own "callers must hold c.mu"
  precondition, even though every such test is single-goroutine.
- TestUnifiedCostMicros case 2: replace a want that called costMicros
  (the function under indirect test) with the literal 11_250_000, hand-
  derived from builtinPricing["gpt-5"] (InputPerM 1.25, OutputPerM 10)
  at 1M prompt + 1M completion tokens.
- TestRedisStore_Get_DownServer_ReturnsError: assert err.Error() contains
  "redisStore: get", not just that an error occurred.

Report corrected: the earlier claim that all new tests were table-driven
was inaccurate (actual split 8/16 at review time); documented as a
deliberate choice, not an oversight — six single-scenario tests stay flat
since a one-row table adds structure without adding coverage.

Gate: go test ./... -count=1 (pass), -race (pass), gofmt (clean), vet
(clean).
This commit is contained in:
2026-08-20 21:42:40 +01:00
parent aee3908bc4
commit 7621733c88
3 changed files with 57 additions and 24 deletions
+2
View File
@@ -4,6 +4,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -181,4 +182,5 @@ func TestRedisStore_Get_DownServer_ReturnsError(t *testing.T) {
store := newRedisStore(newRESPClient(deadAddr, "", 0))
_, err := store.get("k")
require.Error(t, err)
assert.Contains(t, err.Error(), "redisStore: get")
}