Skip to content

feat: add test setup helpers to Lab builder - #44

Merged
Frando merged 2 commits into
mainfrom
feat/test-api
Jul 23, 2026
Merged

feat: add test setup helpers to Lab builder#44
Frando merged 2 commits into
mainfrom
feat/test-api

Conversation

@Frando

@Frando Frando commented Jul 22, 2026

Copy link
Copy Markdown
Member

Description

This adds additive helpers on the lab API to remove boilerplate that every patchbay integration test repeats when it initializes a lab.

Today, iroh's patchbay tests (both iroh and iroh-dns-server) do this to auto-label a lab with the test name:

let mut builder = Lab::builder().outdir(OutDir::Exact(dir.clone()));
if let Some(name) = std::thread::current().name() {
    builder = builder.label(name);
}
let lab = builder.build().await?;
let guard = lab.test_guard();

The if let mutable rebind exists only because label() takes a value while the thread name is an Option. It gets copy-pasted across test files.

This PR adds:

  • LabBuilder::label_from_thread() — applies the current thread's name as the label, skipping unnamed threads and the generic runtime names (main, tokio-runtime-worker) so it is safe to call unconditionally. The Rust test harness names each test thread after the test function under the default current-thread #[tokio::test] runtime, which is where this pays off.
  • Lab::for_test(dir) — wraps the whole setup: writes output into dir (OutDir::Exact), labels from the thread name, builds, and returns the lab alongside its TestGuard.

The call site collapses to:

let (lab, guard) = Lab::for_test(testdir!()).await?;

or, when a test wants to keep control over the builder:

let lab = Lab::builder()
    .outdir(OutDir::Exact(dir))
    .label_from_thread()
    .build()
    .await?;

Breaking changes

None, only additions

Frando and others added 2 commits July 22, 2026 11:18
Integration tests repeat the same dance to auto-label a lab with the
test name: read std::thread::current().name(), rebind the builder
through an if-let, then build and take a test guard. Move that logic
into patchbay.

LabBuilder::label_from_thread() applies the current thread's name as the
label, skipping unnamed threads and the generic runtime names so it is
safe to call unconditionally. The Rust test harness names each test
thread after the test function under the default current-thread
#[tokio::test] runtime, so this labels the lab with the test name.

Lab::for_test(dir) wraps the common test setup end to end: it writes
output directly into dir, labels from the thread name, builds, and
returns the lab alongside its TestGuard.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Frando
Frando merged commit 9f0d703 into main Jul 23, 2026
4 checks passed
Frando added a commit that referenced this pull request Jul 27, 2026
Brings in the merged PRs #43 (LinkLimits folded into LinkCondition with
preset constructors and setters) and #44 (Lab test-setup helpers).

Conflicts resolved:
- patchbay/src/lib.rs: keep NatConfigError (from this branch) in the
  re-export list, drop LinkLimits (removed upstream by #43).
- docs/reference/patterns.md: keep Nat::Moderate (this branch's rename)
  and the new LinkCondition::new().rate_mbit(20) API (from #43).
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