Skip to content

Commit

Permalink
[fix] #2457: Fix tests flakiness related to shut down on panic (#2474)
Browse files Browse the repository at this point in the history
* [fix] #2457: Add shut down on panic configuration

Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>

* [fix] #2457: Update docs

Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>

* [fix] #2457: Fix linter checks

Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>
  • Loading branch information
ales-tsurko committed Jul 14, 2022
1 parent 8c7d9d7 commit bf01205
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ tokio = { version = "1.6.0", features = ["sync", "time", "rt", "io-util", "rt-mu
warp = "0.3"

[dev-dependencies]
serial_test = "0.8.0"
test_network = { version = "=2.0.0-pre-rc.5", path = "../core/test_network" }
3 changes: 3 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct Configuration {
pub private_key: PrivateKey,
/// Disable coloring of the backtrace and error report on panic.
pub disable_panic_terminal_colors: bool,
/// Iroha will shutdown on any panic if this option is set to `true`.
pub shutdown_on_panic: bool,
/// `Kura` related configuration.
#[config(inner)]
pub kura: KuraConfiguration,
Expand Down Expand Up @@ -71,6 +73,7 @@ impl Default for Configuration {
public_key,
private_key,
disable_panic_terminal_colors: bool::default(),
shutdown_on_panic: false,
kura: KuraConfiguration::default(),
sumeragi: sumeragi_configuration,
torii: ToriiConfiguration::default(),
Expand Down
9 changes: 7 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ where

Self::start_listening_signal(Arc::clone(&notify_shutdown))?;

Self::prepare_panic_hook(notify_shutdown);
if config.shutdown_on_panic {
Self::prepare_panic_hook(notify_shutdown);
}

let torii = Some(torii);
Ok(Self {
Expand Down Expand Up @@ -367,10 +369,13 @@ fn domains(configuration: &config::Configuration) -> [Domain; 1] {
mod tests {
use std::{panic, thread};

use serial_test::serial;

use super::*;

#[tokio::test]
#[allow(clippy::panic)]
#[tokio::test]
#[serial]
async fn iroha_should_notify_on_panic() {
let notify = Arc::new(Notify::new());
let hook = panic::take_hook();
Expand Down
11 changes: 11 additions & 0 deletions docs/source/references/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following is the default configuration used by Iroha.
"payload": "282ed9f3cf92811c3818dbc4ae594ed59dc1a2f78e4241e31924e101d6b1fb831c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b"
},
"DISABLE_PANIC_TERMINAL_COLORS": false,
"SHUTDOWN_ON_PANIC": false,
"KURA": {
"INIT_MODE": "strict",
"BLOCK_STORE_PATH": "./blocks",
Expand Down Expand Up @@ -463,6 +464,16 @@ Has type `u64`. Can be configured via environment variable `QUEUE_TRANSACTION_TI
86400000
```

## `shutdown_on_panic`

Iroha will shutdown on any panic if this option is set to `true`.

Has type `bool`. Can be configured via environment variable `IROHA_SHUTDOWN_ON_PANIC`

```json
false
```

## `sumeragi`

`Sumeragi` related configuration.
Expand Down

0 comments on commit bf01205

Please sign in to comment.