Skip to content

test: cover HTTP JSON transport behavior - #15

Merged
NetworkTheoryAppliedResearchInstitute merged 1 commit into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/httpjson-transport-tests
Oct 28, 2026
Merged

NetworkTheoryAppliedResearchInstitute merged 1 commit into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/httpjson-transport-tests

Conversation

@nirmalhk7

Copy link
Copy Markdown
Contributor

The HTTP+JSON transport had no test coverage. Add 52 test cases covering client/server round trips for all six coordinator operations, request rejection, and error handling. Transport statement coverage rises from 0% to 100%.

The tests exercise query escaping for node IDs, byte and timestamp serialization, default and supplied HTTP clients, malformed request/response JSON, missing node IDs, unsupported methods, coordinator failures, cancellation, transport errors, response-body closure, and the 4096-byte error-body limit.

Only two test files change. Production code, dependencies, CI, and quality configuration remain unchanged.

Validation:

  • go test -race -count=1 -coverprofile=/tmp/protocol-httpjson-final-coverage.out ./...: passes; HTTP transport has 100% statement coverage.
  • go vet ./..., go build ./..., and repository-wide gofmt check: pass.
  • python3 testdata/reproduce_spec.py: all 55 checks match.
  • Dependency-leaf check: standard library only.
  • Qlty smell comparison against the base, including tests: no additional findings.
  • git diff --check: passes.

Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
@nirmalhk7
nirmalhk7 force-pushed the nirmal/httpjson-transport-tests branch from 084778f to 3447711 Compare October 24, 2026 19:32
@nirmalhk7
nirmalhk7 marked this pull request as ready for review October 24, 2026 19:58

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nirmal, thanks for this. It's a solid, test-only PR that gives transport/httpjson real coverage where it had none.

What I tested (head 3447711)

  • CI ran on GitHub's merge commit aefcfc6, which is your head merged into current main 4e52c35. All checks passed: gofmt, go vet, go build, go test ./..., conformance (55/55 ALL MATCH), the zero-dependency check and DCO.
  • transport/httpjson now reports "ok" instead of "[no test files]". The other packages give the same results as on main.
  • I read both new files. Your count of 52 cases matches the code.
  • I couldn't run Go tests locally, so these results come from CI on Linux. CI runs go test ./... without -race, so I couldn't reproduce your race-detector run. Reading the code, I don't see a race.

What's good
The assertions are strict, not just "no error":

  • assertCoordinatorCall checks exact routing: one call, the right method and a DeepEqual of the input.
  • The node +/&?=雪 node_id tests query escaping end to end.
  • trackedBody checks that every response body is closed.
  • The 4096-byte error limit is checked by exact length.
  • Every POST is checked for its request Content-Type.
  • The year-10000 timestamp exercises the marshal error path.
  • All 25 bad requests are checked to never reach the coordinator.
  • The exact 500 body is checked.

Everything stays stdlib-only, and the fake hosts use .test.

Small follow-ups (none block this PR)

  1. transport/httpjson/server.go:80: no test checks the 204 that SPEC.md:393-398 says POST routes return, or the 200 for GET. Changing or deleting the WriteHeader still passes. Suggested fix: add a success arm to TestHandlerReturnsCoordinatorErrors that expects 204 with an empty body for POST routes and 200 for /v0/jobs and /v0/fees.
  2. client_test.go:83-94, :98, :124: the cancellation and transport-error tests cover only listing, jobs and fees. Suggested fix: add heartbeat, decline and report cases to invokeRequest and the two method lists.
  3. server.go:38, :51, :76: nothing checks that r.Context() reaches the coordinator, because recordingCoordinator ignores its ctx. Suggested fix: record ctx and assert a context.WithValue marker set with httptest.NewRequest(...).WithContext(...).
  4. client.go:75: nothing tests status 300 (the upper edge of the 2xx check). Suggested fix: add a case with status 300, body "moved" and expected error "sohocloud: GET /v0/jobs: status 300: moved".
  5. Optional, server.go:93: the response Content-Type isn't asserted. This only matters if SPEC starts requiring it.

Thanks again for the careful work.

Approved at the tested commit 3447711 on Jodson Graves's instruction.

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.

2 participants