feat: add test setup helpers to Lab builder - #44
Merged
Merged
Conversation
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
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
irohandiroh-dns-server) do this to auto-label a lab with the test name:The
if letmutable rebind exists only becauselabel()takes a value while the thread name is anOption. 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 intodir(OutDir::Exact), labels from the thread name, builds, and returns the lab alongside itsTestGuard.The call site collapses to:
or, when a test wants to keep control over the builder:
Breaking changes
None, only additions