mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
Use tokio runtime handle instead of TaskExecutor abstraction (#9737)
* Use tokio runtime handle instead of TaskExecutor abstraction Before this pr we had the `TaskExecutor` abstraction which theoretically allowed that any futures executor could have been used. However, this was never tested and is currently not really required. Anyone running a node currently only used tokio and nothing else (because this was hard coded in CLI). So, this pr removes the `TaskExecutor` abstraction and relies directly on the tokio runtime handle. Besides this changes, this pr also makes sure that the http and ws rpc server use the same tokio runtime. This fixes a panic that occurred when you drop the rpc servers inside an async function (tokio doesn't like that a tokio runtime is dropped in the async context of another tokio runtime). As we don't use any custom runtime in the http rpc server anymore, this pr also removes the `rpc-http-threads` cli argument. If external parties complain that there aren't enough threads for the rpc server, we could bring support for increasing the thread count of the tokio runtime. * FMT * Fix try runtime * Fix integration tests and some other optimizations * Remove warnings
This commit is contained in:
@@ -16,23 +16,30 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#![cfg(unix)]
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{convert::TryInto, process::Command, thread, time::Duration};
|
||||
use nix::{
|
||||
sys::signal::{
|
||||
kill,
|
||||
Signal::{self, SIGINT, SIGTERM},
|
||||
},
|
||||
unistd::Pid,
|
||||
};
|
||||
use sc_service::Deref;
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
ops::DerefMut,
|
||||
process::{Child, Command},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
pub mod common;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn running_the_node_works_and_can_be_interrupted() {
|
||||
use nix::{
|
||||
sys::signal::{
|
||||
kill,
|
||||
Signal::{self, SIGINT, SIGTERM},
|
||||
},
|
||||
unistd::Pid,
|
||||
};
|
||||
|
||||
fn run_command_and_kill(signal: Signal) {
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
let mut cmd = Command::new(cargo_bin("substrate"))
|
||||
@@ -55,3 +62,57 @@ fn running_the_node_works_and_can_be_interrupted() {
|
||||
run_command_and_kill(SIGINT);
|
||||
run_command_and_kill(SIGTERM);
|
||||
}
|
||||
|
||||
struct KillChildOnDrop(Child);
|
||||
|
||||
impl Drop for KillChildOnDrop {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.0.kill();
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for KillChildOnDrop {
|
||||
type Target = Child;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for KillChildOnDrop {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn running_two_nodes_with_the_same_ws_port_should_work() {
|
||||
fn start_node() -> Child {
|
||||
Command::new(cargo_bin("substrate"))
|
||||
.args(&["--dev", "--tmp", "--ws-port=45789"])
|
||||
.spawn()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
let mut first_node = KillChildOnDrop(start_node());
|
||||
let mut second_node = KillChildOnDrop(start_node());
|
||||
|
||||
thread::sleep(Duration::from_secs(30));
|
||||
|
||||
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()),
|
||||
Some(true),
|
||||
"The first node must exit gracefully",
|
||||
);
|
||||
assert_eq!(
|
||||
common::wait_for(&mut second_node, 30).map(|x| x.success()),
|
||||
Some(true),
|
||||
"The second node must exit gracefully",
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user