Skip to content

Commit 9d9da74

Browse files
authored
Introduce global::with_locked_writer (#43)
* Flatten type check, fix panic message _GlobalWriter is deprecated for GlobalWriter * Introduce `global::with_locked_writer` New function `global::with_locked_writer` is introduced to allow consistently capturing write output. This function is designed for use in testing output or in other non-reentrant capture cases. This blocks all threads using this function but one from executing so that a deterministic and consistent output is captured. Previously tests could be written with a thread_local writer, however there's a subtle race condition in that approach if the output relies on "paragraph" style text. That race condition occurs because `global::set_writer` not only mutates the writer but also resets the trailing newlines count, which affects the output. This replacement for that behavior should be safer. * Prefer public testing helper * Update test to use `with_locked_writer These are a doc tests, so they already run in their own processes. Now these tests don't need a tempfile, which is nice. * Prefer error over unwrap * Prefer expect over unwrap
1 parent 22662f1 commit 9d9da74

File tree

7 files changed

+387
-142
lines changed

7 files changed

+387
-142
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Add: New function `global::with_locked_writer` is introduced to allow consistently capturing write output. This function is designed for use in testing output or in other non-reentrant capture cases. This blocks all threads using this function but one from executing so that a deterministic and consistent output is captured. Previously tests could be written with a thread_local writer, however there's a subtle race condition in that approach if the output relies on "paragraph" style text (https://github.com/heroku-buildpacks/bullet_stream/pull/43).
6+
57
## v0.9.0 2025/06/05
68

79
- Change: Result of `global::sub_start_timer(...).done()` is no longer "must use". This means it no longer needs `let _ =` for clippy. (https://github.com/heroku-buildpacks/bullet_stream/pull/38)

src/docs/global_done_one.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/docs/global_done_two.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/docs/global_setup.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)