This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
CLI improvements & fixes #4812
Merged
Merged
CLI improvements & fixes #4812
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f862c2c
Initial commit
cecton e67bd7a
WIP
cecton 916b7d5
WIP
cecton 99cdfe6
WIP
cecton 5d9f054
WIP
cecton 70f9cd3
WIP
cecton dae2e91
WIP
cecton c798e75
WIP
cecton 82ebab0
WIP
cecton c447ef0
WIP
cecton 4691645
task_executor is now Arc
cecton c2e14c4
WIP
cecton 91757a4
WIP
cecton eec9c0e
WIP
cecton 95cf751
Added tests and clean-up code
cecton 4fcd2b8
Update branch 'cecton-cli-improvements' from parent 'origin/master'
cecton b8d7cb1
Update branch 'cecton-cli-improvements' from parent 'origin/master'
cecton 54d5e96
Update Cargo.lock
cecton e3e5531
Update client/cli/src/lib.rs
cecton 1b9e1f2
WIP
cecton 8d5894b
Update bin/node/cli/tests/running_the_node_and_interrupt.rs
cecton 1b22ae9
WIP
cecton 1d60093
WIP
cecton 41450d2
Cargo.lock
cecton 1145570
Update branch 'cecton-cli-improvements' from parent 'origin/master'
cecton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
WIP
Forked at: 9195fac Parent branch: origin/master
- Loading branch information
commit 1b9e1f205dc8c89f99ad096b48aa90c79e35b399
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,55 @@ | ||
| // Copyright 2017-2020 Parity Technologies (UK) Ltd. | ||
cecton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // This file is part of Substrate. | ||
|
|
||
| // Substrate is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Substrate is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| use assert_cmd::cargo::cargo_bin; | ||
cecton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use std::process::Command; | ||
| use std::convert::TryInto; | ||
| use std::process::{Child, Command, ExitStatus}; | ||
| use std::thread::sleep; | ||
| use std::time::Duration; | ||
|
|
||
| #[test] | ||
| #[cfg(unix)] | ||
| fn running_the_node_works_and_can_be_interrupted() { | ||
| use libc::{kill, SIGINT, SIGTERM}; | ||
|
|
||
| let mut cmd = Command::new(cargo_bin("substrate")).spawn().unwrap(); | ||
| sleep(Duration::from_secs(30)); | ||
| assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running"); | ||
| unsafe { kill(cmd.id() as i32, SIGINT) }; | ||
| assert!(cmd.wait().unwrap().success(), "the process must exit gracefully after SIGINT"); | ||
|
|
||
| let mut cmd = Command::new(cargo_bin("substrate")).spawn().unwrap(); | ||
| sleep(Duration::from_secs(30)); | ||
| assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running"); | ||
| unsafe { kill(cmd.id() as i32, SIGTERM) }; | ||
| assert!(cmd.wait().unwrap().success(), "the process must exit gracefully after SIGTERM"); | ||
| use nix::sys::signal::{kill, Signal::{self, SIGINT, SIGTERM}}; | ||
| use nix::unistd::Pid; | ||
|
|
||
| fn wait_for(child: &mut Child, secs: usize) -> Option<ExitStatus> { | ||
| for _ in 0..secs { | ||
| match child.try_wait().unwrap() { | ||
| Some(status) => return Some(status), | ||
| None => sleep(Duration::from_secs(1)), | ||
| } | ||
| } | ||
|
|
||
| None | ||
| } | ||
|
|
||
| fn run_command_and_kill(signal: Signal) { | ||
| let mut cmd = Command::new(cargo_bin("substrate")).spawn().unwrap(); | ||
| sleep(Duration::from_secs(30)); | ||
| assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running"); | ||
| kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap(); | ||
| assert_eq!( | ||
| wait_for(&mut cmd, 30).map(|x| x.success()), | ||
| Some(true), | ||
| "the pocess must exit gracefully after signal {}", | ||
| signal, | ||
| ); | ||
| } | ||
|
|
||
| run_command_and_kill(SIGINT); | ||
| run_command_and_kill(SIGTERM); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.