Skip to content

Improve Test Coverage - #43

Merged
RaphiaRa merged 3 commits into
mainfrom
refactor
Aug 10, 2026
Merged

Improve Test Coverage#43
RaphiaRa merged 3 commits into
mainfrom
refactor

Conversation

@RaphiaRa

Copy link
Copy Markdown
Owner
  • Improve test coverage for th_http and th_response
  • Fix issues caught by the tests, including UB in th_http

- th_response_prepare_write finalizes headers and returns a
  th_response_write_plan (iov/file/offset/len), doing no I/O and
  dropping the th_conn dependency from th_response.h entirely
- th_http_write_response now calls th_conn_send itself with the plan
- fix an off-by-one in th_response_set_body_va's slow path: vsnprintf
  was given the formatted length instead of length + 1, truncating
  the last character on printf-style bodies >= 512 bytes

test: rewrite th_response_test.c against the new plan-returning API
- add coverage for th_set_body_from_file (missing/unknown extension,
  unknown root, open failure, explicit Content-Type)
- add coverage for th_printf_body's slow (resize) path
- add coverage for th_add_cookie (attributes, Expires, SameSite)
- add coverage for th_response_reset
…n UB

- too-many-connections check moved from th_http_handle_read_request to
  th_http_upgrader_upgrade: it was gated behind "request has a body
  still to read", so it silently never ran for bodyless requests
  (GET/HEAD/DELETE), and even when it did fire it only rejected after
  fully reading and parsing the request
- now rejects immediately at upgrade time, before any recv
- fix memcpy-param-overlap (caught by ASan) when relocating an
  already-buffered body to the front of the buffer before growing it;
  source and destination legitimately overlap here, so use memmove

test: add coverage for header-too-large, body-too-large,
too-many-connections, HEAD requests, and a body large enough to
trigger the internal buffer growth path
It's a header, not a .c file, so the existing _bench.c exclude
pattern doesn't catch it.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 90.75145% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/th_response_test.c 94.54% 6 Missing ⚠️
src/th_http_test.c 87.50% 0 Missing and 5 partials ⚠️
src/th_http.c 70.00% 2 Missing and 1 partial ⚠️
src/th_response.c 84.61% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@RaphiaRa
RaphiaRa merged commit 754326a into main Aug 10, 2026
3 checks passed
@RaphiaRa
RaphiaRa deleted the refactor branch August 10, 2026 10: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.

2 participants