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
Try to fix flaky temp-base-path-work test
#13505
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02b62e2
Try to fix flaky `temp-base-path-work` test
bkchr 0798557
".git/.scripts/commands/fmt/fmt.sh"
0fb10d2
Capture signals earlier
bkchr f2ed1fd
Rewrite tests to let them having one big timeout
bkchr 700c3b7
Remove unneeded dep
bkchr 358fb1d
Update bin/node/cli/tests/common.rs
bkchr fe2da6b
Review feedback
bkchr 57e9e2b
Merge remote-tracking branch 'origin/master' into bkchr-try-fix-flaky…
bkchr 187e247
Update bin/node/cli/tests/common.rs
bkchr 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
Rewrite tests to let them having one big timeout
- Loading branch information
commit f2ed1fd81d05dc2cc55043a702995351f10b597c
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -18,94 +18,81 @@ | |
|
|
||
| #![cfg(unix)] | ||
| use assert_cmd::cargo::cargo_bin; | ||
| use nix::{ | ||
| sys::signal::{ | ||
| kill, | ||
| Signal::{self, SIGINT, SIGTERM}, | ||
| }, | ||
| unistd::Pid, | ||
| use nix::sys::signal::Signal::{self, SIGINT, SIGTERM}; | ||
| use std::{ | ||
| process::{self, Child, Command}, | ||
| time::Duration, | ||
| }; | ||
| use std::process::{self, Child, Command}; | ||
| use tempfile::tempdir; | ||
|
|
||
| pub mod common; | ||
|
|
||
| #[tokio::test] | ||
| async fn running_the_node_works_and_can_be_interrupted() { | ||
| async fn run_command_and_kill(signal: Signal) { | ||
| let base_path = tempdir().expect("could not create a temp dir"); | ||
| let mut cmd = common::KillChildOnDrop( | ||
| common::run_with_timeout(Duration::from_secs(60 * 10), async move { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If 10 minutes is kind of master timeout, maybe this could be a const (or maybe some default within the function that could be overwritten by env?), just to avoid spreading this hard-coded value over the code. |
||
| async fn run_command_and_kill(signal: Signal) { | ||
| let base_path = tempdir().expect("could not create a temp dir"); | ||
| let mut cmd = common::KillChildOnDrop( | ||
| Command::new(cargo_bin("substrate")) | ||
| .stdout(process::Stdio::piped()) | ||
| .stderr(process::Stdio::piped()) | ||
| .args(&["--dev", "-d"]) | ||
| .arg(base_path.path()) | ||
| .arg("--db=paritydb") | ||
| .arg("--no-hardware-benchmarks") | ||
| .spawn() | ||
| .unwrap(), | ||
| ); | ||
|
|
||
| let stderr = cmd.stderr.take().unwrap(); | ||
|
|
||
| let (ws_url, _) = common::find_ws_url_from_output(stderr); | ||
|
|
||
| common::wait_n_finalized_blocks(3, &ws_url).await; | ||
|
|
||
| cmd.assert_still_running(); | ||
|
|
||
| cmd.stop_with_signal(signal); | ||
|
|
||
| // Check if the database was closed gracefully. If it was not, | ||
| // there may exist a ref cycle that prevents the Client from being dropped properly. | ||
| // | ||
| // parity-db only writes the stats file on clean shutdown. | ||
| let stats_file = base_path.path().join("chains/dev/paritydb/full/stats.txt"); | ||
| assert!(std::path::Path::exists(&stats_file)); | ||
| } | ||
|
|
||
| run_command_and_kill(SIGINT).await; | ||
| run_command_and_kill(SIGTERM).await; | ||
| }) | ||
| .await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn running_two_nodes_with_the_same_ws_port_should_work() { | ||
| common::run_with_timeout(Duration::from_secs(60 * 10), async move { | ||
| fn start_node() -> Child { | ||
| Command::new(cargo_bin("substrate")) | ||
| .stdout(process::Stdio::piped()) | ||
| .stderr(process::Stdio::piped()) | ||
| .args(&["--dev", "-d"]) | ||
| .arg(base_path.path()) | ||
| .arg("--db=paritydb") | ||
| .arg("--no-hardware-benchmarks") | ||
| .args(&["--dev", "--tmp", "--ws-port=45789", "--no-hardware-benchmarks"]) | ||
| .spawn() | ||
| .unwrap(), | ||
| ); | ||
| .unwrap() | ||
| } | ||
|
|
||
| let stderr = cmd.stderr.take().unwrap(); | ||
| let mut first_node = common::KillChildOnDrop(start_node()); | ||
| let mut second_node = common::KillChildOnDrop(start_node()); | ||
|
|
||
| let stderr = first_node.stderr.take().unwrap(); | ||
| let (ws_url, _) = common::find_ws_url_from_output(stderr); | ||
|
|
||
| common::wait_n_finalized_blocks(3, 30, &ws_url) | ||
| .await | ||
| .expect("Blocks are produced in time"); | ||
| 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!( | ||
| common::wait_for(&mut cmd, 30).map(|x| x.success()), | ||
| Ok(true), | ||
| "the process must exit gracefully after signal {}", | ||
| signal, | ||
| ); | ||
| // Check if the database was closed gracefully. If it was not, | ||
| // there may exist a ref cycle that prevents the Client from being dropped properly. | ||
| // | ||
| // parity-db only writes the stats file on clean shutdown. | ||
| let stats_file = base_path.path().join("chains/dev/paritydb/full/stats.txt"); | ||
| assert!(std::path::Path::exists(&stats_file)); | ||
| } | ||
|
|
||
| run_command_and_kill(SIGINT).await; | ||
| run_command_and_kill(SIGTERM).await; | ||
| } | ||
| common::wait_n_finalized_blocks(3, &ws_url).await; | ||
|
|
||
| #[tokio::test] | ||
| async fn running_two_nodes_with_the_same_ws_port_should_work() { | ||
| fn start_node() -> Child { | ||
| Command::new(cargo_bin("substrate")) | ||
| .stdout(process::Stdio::piped()) | ||
| .stderr(process::Stdio::piped()) | ||
| .args(&["--dev", "--tmp", "--ws-port=45789", "--no-hardware-benchmarks"]) | ||
| .spawn() | ||
| .unwrap() | ||
| } | ||
|
|
||
| let mut first_node = common::KillChildOnDrop(start_node()); | ||
| let mut second_node = common::KillChildOnDrop(start_node()); | ||
|
|
||
| let stderr = first_node.stderr.take().unwrap(); | ||
| let (ws_url, _) = common::find_ws_url_from_output(stderr); | ||
|
|
||
| common::wait_n_finalized_blocks(3, 30, &ws_url).await.unwrap(); | ||
|
|
||
| assert!(first_node.try_wait().unwrap().is_none(), "The first node should still be running"); | ||
| assert!(second_node.try_wait().unwrap().is_none(), "The second node should still be running"); | ||
|
|
||
| kill(Pid::from_raw(first_node.id().try_into().unwrap()), SIGINT).unwrap(); | ||
| kill(Pid::from_raw(second_node.id().try_into().unwrap()), SIGINT).unwrap(); | ||
|
|
||
| assert_eq!( | ||
| common::wait_for(&mut first_node, 30).map(|x| x.success()), | ||
| Ok(true), | ||
| "The first node must exit gracefully", | ||
| ); | ||
| assert_eq!( | ||
| common::wait_for(&mut second_node, 30).map(|x| x.success()), | ||
| Ok(true), | ||
| "The second node must exit gracefully", | ||
| ); | ||
| first_node.assert_still_running(); | ||
| second_node.assert_still_running(); | ||
|
|
||
| first_node.stop(); | ||
| second_node.stop(); | ||
| }) | ||
| .await; | ||
| } | ||
Oops, something went wrong.
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.