feat(test): show sub-millisecond test durations#35200
Open
lunadogbot wants to merge 2 commits into
Open
Conversation
Test durations under 1ms were truncated to 0ms in the test reporter output, making fast tests look like they took no time at all. Thread the full `Duration` through `TestEvent` and the reporter trait instead of truncating to integer milliseconds, and render sub-millisecond durations with fractional millisecond precision (e.g. `0.523ms`). This also gives the JUnit reporter more precise timings. Closes #30785 https://claude.ai/code/session_012SJDri5NiiSbGVrYq6hsNQ
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.
Problem
Test durations under 1ms were truncated to
0msin the test reporter output, because the elapsed time was converted withduration.as_millis() as u64before reaching the reporters. This made fast tests look like they took no time at all:Closes #30785
Changes
Following the maintainer's guidance in the issue, the full
Durationis now threaded through the test pipeline instead of being pre-truncated to milliseconds:TestEvent::Result,Slow, andStepResultnow carry aDurationinstead ofu64milliseconds.pretty,dot,tap,junit,compound, plus the LSP test reporter) now take aDuration.display::human_elapsednow accepts aDurationand renders sub-millisecond durations in microseconds (µs) or nanoseconds (ns), matching the units already used by thedeno benchreporter. Output for durations ≥ 1ms is unchanged.After the change:
Notes
Date.now(). That was left out of scope to keep this change focused on the top-level test durations the issue is about; the millisecond value is converted to aDurationat the op boundary so there's no behavior change there.([WILDCARD]), so they remain compatible.Tests
test_human_elapsed_sub_millisecondcovering thens/µs/msboundaries, and updatedtest_human_elapsedfor the new signature.https://claude.ai/code/session_012SJDri5NiiSbGVrYq6hsNQ
Generated by Claude Code