Skip to content
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

Ensure test library issues json string line-by-line #109729

Merged

Conversation

raoulstrackx
Copy link
Contributor

#108659 introduces a custom test display implementation. It does so by using libtest to output json. The stdout is read line by line and parsed. The code trims the line read and checks whether it starts with a { and ends with a }.

Unfortunately, there is a race condition in how json data is written to stdout. The write_message function calls self.out.write_all repeatedly to write a buffer that contains (partial) json data, or a new line. There is no lock around the self.out.write_all functions. Similarly, the write_message function itself is called with only partial json data. As these functions are called from concurrent threads, this may result in json data ending up on the same stdout line. This PR avoids this by buffering the complete json data before issuing a single self.out.write_all.

(#109484 implemented a partial fix for this issue; it only avoids that failed json parsing would result in a panic.)

cc: @jethrogb, @pietroalbini

@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2023

r? @cuviper

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 29, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@raoulstrackx
Copy link
Contributor Author

r? @pietroalbini could you review?

@rustbot rustbot assigned pietroalbini and unassigned cuviper Mar 29, 2023
Copy link
Member

@pietroalbini pietroalbini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks great! A few calls can be simplified though, left a comment on one of them.

library/test/src/formatters/json.rs Outdated Show resolved Hide resolved
@raoulstrackx raoulstrackx force-pushed the raoul/bugfix_libtest_json_synchronization branch from 8c0f6f9 to 0a30ad8 Compare April 3, 2023 10:58
@raoulstrackx raoulstrackx force-pushed the raoul/bugfix_libtest_json_synchronization branch from 0a30ad8 to cd279eb Compare April 3, 2023 11:06
@rust-log-analyzer

This comment has been minimized.

@raoulstrackx raoulstrackx force-pushed the raoul/bugfix_libtest_json_synchronization branch from cd279eb to 0ddde08 Compare April 4, 2023 09:10
@rust-log-analyzer

This comment has been minimized.

@raoulstrackx raoulstrackx force-pushed the raoul/bugfix_libtest_json_synchronization branch from 0ddde08 to 39e000e Compare April 4, 2023 12:03
@raoulstrackx
Copy link
Contributor Author

@pietroalbini when you have time, can you have another look at this PR? Thank you!

@bors
Copy link
Contributor

bors commented Apr 29, 2023

☔ The latest upstream changes (presumably #110643) made this pull request unmergeable. Please resolve the merge conflicts.

@raoulstrackx raoulstrackx force-pushed the raoul/bugfix_libtest_json_synchronization branch from 39e000e to a18b750 Compare May 1, 2023 09:38
@raoulstrackx
Copy link
Contributor Author

Can this have a review please?

@pietroalbini
Copy link
Member

Sorry for the delay!

@bors r+ rollup=iffy

@bors
Copy link
Contributor

bors commented May 2, 2023

📌 Commit a18b750 has been approved by pietroalbini

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2023
@bors
Copy link
Contributor

bors commented May 2, 2023

⌛ Testing commit a18b750 with merge b4571be...

@bors
Copy link
Contributor

bors commented May 3, 2023

☀️ Test successful - checks-actions
Approved by: pietroalbini
Pushing b4571be to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 3, 2023
@bors bors merged commit b4571be into rust-lang:master May 3, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 3, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b4571be): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.7%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.9% [2.9%, 2.9%] 1
Improvements ✅
(primary)
-3.3% [-3.3%, -3.3%] 1
Improvements ✅
(secondary)
-2.5% [-3.3%, -2.1%] 3
All ❌✅ (primary) -3.3% [-3.3%, -3.3%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 656.048s -> 657.453s (0.21%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants