Skip to content

Commit

Permalink
Avoid panic while panicking because of actix isn't running (#2178)
Browse files Browse the repository at this point in the history
Some of our tests don't have actix running. @Kouprin found when assert in such tests failed it's not able to see which test fails, only `thread panicked while panicking`. So check actix is running and only shutdown it if so fix this.

Test Plan
---------
```
#[test] 
fn test_assert() {
init_stop_on_panic();
assert(false);
}
```
should give assert fails instead of `thread panicked while panicking`
  • Loading branch information
ailisp authored Feb 25, 2020
1 parent 29cb252 commit f0409d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ expensive_tests = []
regression_tests = []
old_tests = []
adversarial = ["near/adversarial", "near-jsonrpc/adversarial"]

[patch.crates-io]
actix-rt = { git = "https://github.com/actix/actix-net", rev="602db1779eb51d60e0fe5a33d725d1d7fdf540fd" }
4 changes: 3 additions & 1 deletion core/primitives/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ pub fn init_stop_on_panic() {
let default_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
default_hook(info);
actix::System::with_current(|sys| sys.stop_with_code(1));
if actix::System::is_set() {
actix::System::with_current(|sys| sys.stop_with_code(1));
}
}));
})
}
Expand Down

0 comments on commit f0409d4

Please sign in to comment.