tox-dev / tox-dev/peryx

Share one controlled-peer test harness

Closed
#2,124 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:tests priority:P3 type:test
Dominant language
Rust
Stars
4
Forks
1
Avg merge
3h 7m
Merged PRs (30d)
523

Description

Problem

Four copies of the same test harness now exist, each written for one crate's needs: silent_peer in crates/peryx-ha-distributed/tests/unit/raft/network_tests.rs, answer_beat in the same crate's beacon_tests.rs, ControlledServer in crates/peryx-upstream/tests/unit/client/deadline_tests.rs, and the bounded variant added by PR #2117.

They all do the same three things: stand up a raw peer on a real socket, run the tokio clock across the I/O rather than holding a paused clock over it, and bound the accept and read so a dial that never arrives fails instead of hanging.

The duplication is not merely repetition. Each copy resumes the clock at a different call depth, which is why the _paused-clock-contract check added in PR #2122 has to resolve calls transitively through a file to decide whether a test is safe. A single shared harness would let that check test for one known call instead of walking the graph.

Example

Three of the four deadline_tests.rs cases clear the contract check via ControlledServer::requested calling run_clock, two calls deep. The raft/network_tests.rs cases clear via silent_peer at a different depth. A fifth copy at a new depth is the failure mode this issue prevents.

Required change

Extract one harness into peryx-test-support and move the four copies onto it.

The architectural constraint is the one that has broken this crate before: a shared helper in peryx-test-support must not name a type from the crate it helps. Doing that once left peryx-storage's own tests failing with 21 type and privacy errors. Keep the shared harness to third-party types — tokio::net::TcpListener, std::time::Duration, tokio::task::JoinHandle — and let each crate compose its protocol-specific behavior on top.

The copies differ in what the peer does after accepting: one stays silent, one answers a heartbeat, one feeds a response chunk by chunk. That difference belongs to the caller. What is shared is the bind, the accept with a bound, the proof that the request arrived, and the clock discipline.

Simplify _paused-clock-contract to recognise the shared harness once the copies are gone, rather than resolving calls transitively.

Acceptance criteria

  • One harness in peryx-test-support, named after what it does rather than after a crate.
  • All four call sites use it, and no copy remains.
  • The harness names no type from any crate that consumes it.
  • Every test that used a copy still fails under the mutations its own pull request established — halved timing, doubled timing, behavior removed. A refactor that quietly weakens an assertion is the risk here.
  • _paused-clock-contract recognises the shared harness directly.

Boundary

Test harness consolidation. No production change, and no change to what any test asserts. If moving a copy reveals that one of them was asserting something weaker than its siblings, say so rather than silently levelling them.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the four harness implementations in crates/peryx-ha-distributed/tests/unit/raft/network_tests.rs, its beacon_tests.rs, crates/peryx-upstream/tests/unit/client/deadline_tests.rs, and the bounded variant from PR #2117, then inspect peryx-test-support and _paused-clock-contract. Move only the shared socket, bounded accept/read, arrival proof, and clock-discipline behavior; preserve each protocol-specific callback and its existing mutation-tested assertions. Done means all four sites use one dependency-neutral harness and the contract check recognises it directly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.