Skip to content

Commit 571121c

Browse files
committed
fix journey tests; improve panic handling when --progress is used.
1 parent 589fb57 commit 571121c

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

Diff for: src/shared.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -165,26 +165,30 @@ pub mod pretty {
165165
tx.send(Event::UiDone).ok();
166166
}
167167
});
168-
std::thread::spawn(move || {
168+
let thread = std::thread::spawn(move || {
169169
// We might have something interesting to show, which would be hidden by the alternate screen if there is a progress TUI
170170
// We know that the printing happens at the end, so this is fine.
171171
let mut out = Vec::new();
172172
let res = run(progress::DoOrDiscard::from(Some(sub_progress)), &mut out, &mut stderr());
173173
tx.send(Event::ComputationDone(res, out)).ok();
174174
});
175175
loop {
176-
match rx.recv()? {
177-
Event::UiDone => {
176+
match rx.recv() {
177+
Ok(Event::UiDone) => {
178178
// We don't know why the UI is done, usually it's the user aborting.
179179
// We need the computation to stop as well so let's wait for that to happen
180180
gix::interrupt::trigger();
181181
continue;
182182
}
183-
Event::ComputationDone(res, out) => {
183+
Ok(Event::ComputationDone(res, out)) => {
184184
ui_handle.join().ok();
185185
stdout().write_all(&out)?;
186186
break res;
187187
}
188+
Err(_err) => match thread.join() {
189+
Ok(()) => unreachable!("BUG: We shouldn't fail to receive unless the thread has panicked"),
190+
Err(panic) => std::panic::resume_unwind(panic),
191+
},
188192
}
189193
}
190194
}

Diff for: tests/journey/ein.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ title "Porcelain ${kind}"
2323
(with "progress option set"
2424
it "fails as expected" && {
2525
WITH_SNAPSHOT="$snapshot/expected-failure-in-thread-with-progress" \
26-
expect_run_sh $WITH_FAILURE "$exe --progress panic"
26+
expect_run_sh 101 "$exe --progress panic"
2727
}
2828
)
2929
)

Diff for: tests/snapshots/panic-behaviour/expected-failure

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:34:42
1+
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:39:42
22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:34:42
1+
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:39:42
22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
33

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

0 commit comments

Comments
 (0)