Repository navigation
Serve raw HTTP bytes from the shared test fixture #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leynos
wants to merge
3
commits into
main
Choose a base branch
from
issue-743-raw-response-fixture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //! Environment overrides for the fixture's timeouts. | ||
| //! | ||
| //! The fixture's deadlines are tunable so a slow machine can be given longer | ||
| //! than a default that suits a fast one. An override arrives as a string, so | ||
| //! this module owns the parsing, the fallback when it does not parse, and the | ||
| //! redaction that keeps a caller-supplied value out of the log. | ||
|
|
||
| use std::{fmt, time::Duration}; | ||
|
|
||
| use mockable::Env; | ||
|
|
||
| #[cfg(test)] | ||
| use std::{cell::RefCell, thread_local}; | ||
|
|
||
| #[cfg(test)] | ||
| thread_local! { | ||
| /// Warnings recorded for assertions by the fixture's own tests. | ||
| /// | ||
| /// A `tracing` subscriber would be the production path, but a unit test | ||
| /// cannot observe one without a global subscriber, so the test build | ||
| /// captures into a thread-local instead. | ||
| pub(super) static DURATION_WARNINGS: RefCell<Vec<String>> = | ||
| const { RefCell::new(Vec::new()) }; | ||
| } | ||
|
|
||
| /// Read `var` as whole milliseconds, falling back to `default` when unset or | ||
| /// unparsable. | ||
| pub(super) fn duration_from_env(env: &impl Env, var: &str, default: Duration) -> Duration { | ||
| env.raw(var).map_or(default, |value| { | ||
| let trimmed = value.trim(); | ||
| match trimmed.parse::<u64>() { | ||
| Ok(ms) => Duration::from_millis(ms), | ||
| Err(err) => { | ||
| log_duration_parse_error(var, trimmed.len(), &err); | ||
| default | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| /// Report an unparsable duration override without echoing its value. | ||
| /// | ||
| /// The value is redacted: an environment variable's contents are outside this | ||
| /// crate's control, and logging them verbatim would put whatever the caller | ||
| /// exported into the log. `err` already names the bounded parse failure, and | ||
| /// `value_len` distinguishes an empty override from a malformed one, which is | ||
| /// all the diagnosis this fixture needs. | ||
| fn log_duration_parse_error(var: &str, value_len: usize, err: &dyn fmt::Display) { | ||
| #[cfg(test)] | ||
| { | ||
| record_duration_warning(format!( | ||
| "ignoring invalid {var}: {err} (value redacted, {value_len} bytes)" | ||
| )); | ||
| } | ||
|
|
||
| #[cfg(not(test))] | ||
| { | ||
| tracing::warn!( | ||
| variable = var, | ||
| value_len, | ||
| error = %err, | ||
| "ignoring invalid fixture duration" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Record a warning for the fixture's own tests to assert on. | ||
| #[cfg(test)] | ||
| fn record_duration_warning(message: String) { | ||
| DURATION_WARNINGS.with(|warnings| warnings.borrow_mut().push(message)); | ||
| } | ||
|
|
||
| /// Take the warnings recorded so far on this thread, leaving the buffer empty. | ||
| #[cfg(test)] | ||
| pub(super) fn take_duration_warnings() -> Vec<String> { | ||
| DURATION_WARNINGS.with(|warnings| warnings.borrow_mut().drain(..).collect()) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the extraction of the existing environment and server-spawning code into a separate commit after the raw-response functionality. Combining that refactor with the behavioural change makes this commit non-atomic and prevents reviewers or maintainers from validating, reverting, or bisecting the functional change independently, contrary to the repository's explicit post-change refactoring workflow.
AGENTS.md reference: AGENTS.md:L126-L134
Useful? React with 👍 / 👎.