Skip to content

test: rewrite unit tests with testify/goleak; coverage 100% (#10)#19

Merged
millerjp merged 2 commits into
mainfrom
feature/unit-test-rewrite
Apr 20, 2026
Merged

test: rewrite unit tests with testify/goleak; coverage 100% (#10)#19
millerjp merged 2 commits into
mainfrom
feature/unit-test-rewrite

Conversation

@millerjp

Copy link
Copy Markdown

Summary

Replaces the fork's internal-package smoke test with a comprehensive external-package suite and raises the CI coverage gate to the AxonOps 95% target. Coverage on syncmap.go jumps from 36.1% to 100.0%.

Closes #10.

What's in this PR

Two commits, bisectable:

  1. test: rewrite unit tests in external package with testify/goleak (#10) — replaces syncmap_smoke_test.go with syncmap_test.go, adds testify v1.11.1 and goleak v1.3.0 to go.mod, creates go.sum.
  2. ci: raise coverage threshold to 95% (#10) — flips threshold=35.095.0 in .github/workflows/ci.yml, removes the TODO(#11) comment.

Test structure

  • package syncmap_test (black-box).
  • TestMain wires goleak.VerifyTestMain(m) as the single package-wide leak hook (per-test VerifyNone(t) was dropped because t.Parallel() siblings would detect each other's goroutines).
  • 15 top-level TestX functions, 33 subtests, 48 total t.Parallel() calls.
  • Every public method: Load, Store, LoadOrStore, LoadAndDelete, Delete, Range, Len, Map, Keys, Items — each with happy path, missing-key, zero-value distinction, and edge cases.
  • Four concurrency tests:
    • TestConcurrentWritersReaders — 16 writers × 8 readers × 1000 ops, writer-id bounds asserted on loaded values.
    • TestLoadOrStoreContention — 100 goroutines, single key, exactly one "stored" winner (via atomic.Int32).
    • TestRangeDuringWrites — writers cycle through the whole keyspace concurrently with Range; subset invariant asserted per sync.Map contract.
    • TestDeleteDuringRange — deleter concurrent with Range; no panic; observed (k, v) pairs satisfy k == v.
  • Every concurrency test stable over go test -race -count=10.

Coverage — per method

Load               100.0%
Store              100.0%
LoadOrStore        100.0%
LoadAndDelete      100.0%
Delete             100.0%
Range              100.0%
Len                100.0%
Map                100.0%
Keys               100.0%
Items              100.0%
total              100.0%

Agent gates

  • test-analyst (pre-code): scenario plan
  • test-writer: produced the initial file
  • test-analyst (post-code): confirmed every scenario landed, branches are genuinely exercised (!ok in Load, !l in LoadAndDelete, both Range callback paths)
  • code-reviewer: approved with two IMPORTANT tightenings — reader keyspace variation in TestConcurrentWritersReaders, whole-keyspace writer loop in TestRangeDuringWrites. Both applied.
  • security-reviewer: no blockers; race-clean, no over-strong assertions, no panic paths in test code
  • devops (on the threshold flip): approved
  • go-quality: all checks pass (the earlier "FAIL" on go mod tidy + diff was the pre-commit dirty state, resolved on commit)
  • commit-message-reviewer: both commit messages pass

Local validation

$ make check
… (fmt-check vet lint tidy-check test test-bdd coverage security)
coverage: 100.0% of statements
No vulnerabilities found.
(exit 0)

$ go test -race -count=10 -run 'TestConcurrent|TestLoadOrStoreContention|TestRangeDuringWrites|TestDeleteDuringRange' ./...
ok  github.com/axonops/syncmap  1.609s

Test plan

  • All CI jobs green (especially the newly-strict coverage gate)
  • test matrix stable on both ubuntu-latest and macos-latest
  • Coverage artefact downloadable and reports 100.0%

Replace the internal-package smoke test with a comprehensive black-box
suite. Every public method has a dedicated TestX with subtests covering
happy path, missing/zero-value distinctions, and edge cases. Four
concurrency tests exercise store-read contention, LoadOrStore
idempotency, Range-during-writes, and Delete-during-Range — each
stable over -count=10 runs under -race.

Coverage rises from 36.1% to 100.0% of statements in syncmap.go.

Test deps added to go.mod: testify v1.11.1 and goleak v1.3.0. goleak
wired via a single TestMain hook (VerifyTestMain) — per-test
VerifyNone calls were dropped because t.Parallel() siblings would
detect each other's goroutines.

The CI coverage gate is left at 35% in this commit and raised to 95%
in a follow-up commit on the same branch so the threshold flip is
bisectable.
The preceding commit lifted coverage of syncmap.go to 100%. Flip the
CI gate in ci.yml from the interim 35% floor to the AxonOps 95%
target, and remove the TODO(#11) comment block. The release workflow
at release.yml already enforced 95% independently.
@millerjp millerjp merged commit 4f59887 into main Apr 20, 2026
13 checks passed
@millerjp millerjp deleted the feature/unit-test-rewrite branch April 20, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: rewrite unit tests to external package with testify/goleak; coverage ≥95%

1 participant