Skip to content

tests: cover the RTMP chunk layer and trace hex helper#32

Merged
Soulhackzlol merged 1 commit into
mainfrom
tests/rtmp-chunk-coverage
Jul 4, 2026
Merged

tests: cover the RTMP chunk layer and trace hex helper#32
Soulhackzlol merged 1 commit into
mainfrom
tests/rtmp-chunk-coverage

Conversation

@Soulhackzlol

Copy link
Copy Markdown
Owner

What

Adds unit coverage for rtmp/chunk.rs and trace::hex_prefix. The chunk stream reader/writer was only exercised through the end-to-end job before this.

Why

Our ChunkWriter only ever emits fmt-0 headers plus fmt-3 continuations. That means the reader's fmt-1, fmt-2, and fmt-3-replay decode paths, the extended-timestamp corner, and the in-band control messages had no direct test, even though OBS and Twitch use all of them on every connection. If a refactor broke one of those paths, only a live stream would have caught it.

What's covered

15 new cases in rtmp/chunk.rs:

  • Writer and reader round-trips: small message, fragmented across chunks, extended timestamp, and extended timestamp combined with fragmentation. These check the encoder and decoder against each other rather than against a fixed byte blob.
  • Reader-only decode paths the writer never produces: fmt-1 (reuses the message stream id, advances the timestamp by a delta), fmt-2 (reuses length/type/stream), fmt-3 (replays the previous header).
  • In-band control handling: Set-Chunk-Size is applied and swallowed, Window-Ack-Size lowers the acknowledgement threshold and only fires one ack per watermark.
  • Basic-header CSID range encoding (1, 2, and 3 byte forms) and the u24 helper round-trip.
  • Malformed input returns an error instead of panicking: truncated header, truncated payload, zero-length message.

4 new pure tests for trace::hex_prefix (formatting, boundary, truncation suffix).

The socket-driving files (client.rs, server.rs, handshake.rs, tcp.rs, sink.rs) are intentionally left to the e2e job. Unit-mocking those would add brittle tests without much signal. chunk.rs was the one file with real parsing logic on the untrusted-input path, so that's where the coverage went.

Verification

  • cargo fmt --all -- --check clean
  • cargo clippy --all-targets -- -D warnings clean
  • cargo test --release: 229 passed, 0 failed, 1 ignored (the existing GitHub-hitting test)

Test count went from 210 to 229. Both READMEs and the changelog are updated to match.

The chunk stream reader/writer was only exercised by the e2e job. Since
our ChunkWriter only ever emits fmt-0 + fmt-3 continuations, the reader's
fmt-1/2/3 decode paths, the extended-timestamp handling, and the in-band
control messages had no direct coverage even though OBS and Twitch drive
all of them on every connection.

Adds 15 tests to rtmp/chunk.rs:
- writer/reader round-trips (small, fragmented, extended-timestamp, and
  extended-timestamp across fragmentation) so the encoder and decoder are
  checked against each other
- reader-only fmt-1/fmt-2/fmt-3 header decoding, which the writer never
  produces
- in-band Set-Chunk-Size and Window-Ack-Size handling
- basic-header CSID range encoding and u24 round-trip
- malformed input (truncated header, truncated payload, zero-length
  message) returning an error instead of panicking

Also adds 4 pure tests for trace::hex_prefix.

Test count 210 -> 229. Updated both READMEs and the changelog.
@Soulhackzlol
Soulhackzlol merged commit 885b6cb into main Jul 4, 2026
4 checks passed
@Soulhackzlol
Soulhackzlol deleted the tests/rtmp-chunk-coverage branch July 4, 2026 21:56
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.

1 participant