Skip to content

Commit

Permalink
fix journey tests; improve panic handling when --progress is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Feb 17, 2023
1 parent 589fb57 commit 571121c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,30 @@ pub mod pretty {
tx.send(Event::UiDone).ok();
}
});
std::thread::spawn(move || {
let thread = std::thread::spawn(move || {
// We might have something interesting to show, which would be hidden by the alternate screen if there is a progress TUI
// We know that the printing happens at the end, so this is fine.
let mut out = Vec::new();
let res = run(progress::DoOrDiscard::from(Some(sub_progress)), &mut out, &mut stderr());
tx.send(Event::ComputationDone(res, out)).ok();
});
loop {
match rx.recv()? {
Event::UiDone => {
match rx.recv() {
Ok(Event::UiDone) => {
// We don't know why the UI is done, usually it's the user aborting.
// We need the computation to stop as well so let's wait for that to happen
gix::interrupt::trigger();
continue;
}
Event::ComputationDone(res, out) => {
Ok(Event::ComputationDone(res, out)) => {
ui_handle.join().ok();
stdout().write_all(&out)?;
break res;
}
Err(_err) => match thread.join() {
Ok(()) => unreachable!("BUG: We shouldn't fail to receive unless the thread has panicked"),
Err(panic) => std::panic::resume_unwind(panic),
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/journey/ein.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ title "Porcelain ${kind}"
(with "progress option set"
it "fails as expected" && {
WITH_SNAPSHOT="$snapshot/expected-failure-in-thread-with-progress" \
expect_run_sh $WITH_FAILURE "$exe --progress panic"
expect_run_sh 101 "$exe --progress panic"
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/panic-behaviour/expected-failure
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:34:42
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:39:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2 changes: 1 addition & 1 deletion tests/snapshots/panic-behaviour/expected-failure-in-thread
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:34:42
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:39:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[?1049h[?25lthread '<unnamed>' panicked at 'something went very wrong', src/porcelain/main.rs:34:42
[?1049h[?25lthread '<unnamed>' panicked at 'something went very wrong', src/porcelain/main.rs:39:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[?25h[?1049lError: receiving on a closed channel
[?25h[?1049l

0 comments on commit 571121c

Please sign in to comment.