|
| 1 | +// Copyright 2020 Parity Technologies (UK) Ltd. |
| 2 | +// This file is part of Substrate. |
| 3 | + |
| 4 | +// Substrate is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// Substrate is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Substrate. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +use assert_cmd::cargo::cargo_bin; |
| 18 | +use std::{convert::TryInto, process::Command, thread, time::Duration, fs}; |
| 19 | + |
| 20 | +mod common; |
| 21 | + |
| 22 | +#[test] |
| 23 | +#[cfg(unix)] |
| 24 | +fn polkadot_argument_parsing() { |
| 25 | + use nix::sys::signal::{kill, Signal::{self, SIGINT, SIGTERM}}; |
| 26 | + use nix::unistd::Pid; |
| 27 | + |
| 28 | + fn run_command_and_kill(signal: Signal) { |
| 29 | + let _ = fs::remove_dir_all("polkadot_argument_parsing"); |
| 30 | + let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator")) |
| 31 | + .args(&[ |
| 32 | + "-d", "polkadot_argument_parsing", "--", "--bootnodes", |
| 33 | + "/ip4/127.0.0.1/tcp/30333/p2p/Qmbx43psh7LVkrYTRXisUpzCubbgYojkejzAgj5mteDnxy", |
| 34 | + "--bootnodes", |
| 35 | + "/ip4/127.0.0.1/tcp/50500/p2p/Qma6SpS7tzfCrhtgEVKR9Uhjmuv55ovC3kY6y6rPBxpWd", |
| 36 | + ]) |
| 37 | + .spawn() |
| 38 | + .unwrap(); |
| 39 | + |
| 40 | + thread::sleep(Duration::from_secs(20)); |
| 41 | + assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running"); |
| 42 | + kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap(); |
| 43 | + assert_eq!( |
| 44 | + common::wait_for(&mut cmd, 30).map(|x| x.success()), |
| 45 | + Some(true), |
| 46 | + "the process must exit gracefully after signal {}", |
| 47 | + signal, |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + run_command_and_kill(SIGINT); |
| 52 | + run_command_and_kill(SIGTERM); |
| 53 | +} |
0 commit comments