Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve overall test time #60

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@
# Substrate
*.log
*.out

# Linux
*~
.fuse_hidden*
.directory
.Trash-*
.nfs*

# macOS
.DS_Store
._*
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,7 @@ async fn create_snapshot_works() {
let port = 45789;
let ws_url = format!("ws://localhost:{}", port);

// Spawn a dev node.
let _ = std::thread::spawn(move || {
match common::start_node_inline(vec![
"--no-hardware-benchmarks",
"--dev",
format!("--rpc-port={}", port).as_str(),
]) {
Ok(_) => {}
Err(e) => {
panic!("Node exited with error: {}", e);
}
}
});
// Wait some time to ensure the node is warmed up.
std::thread::sleep(Duration::from_secs(90));
crate::start_dev_node(port);

// Run the command with tokio
let temp_dir = tempfile::Builder::new()
Expand All @@ -56,7 +42,48 @@ async fn create_snapshot_works() {
.expect("Failed to create a tempdir");
let snap_file_path = temp_dir.path().join("snapshot.snap");

common::run_with_timeout(Duration::from_secs(60), async move {
common::run_with_timeout(Duration::from_secs(360), async move {
async fn block_hash(block_number: u64, uri: &str, timeout: u64) -> Result<Hash, String> {
use std::time::Duration;

use node_primitives::Header;
use sp_rpc::{list::ListOrValue, number::NumberOrHex};
use substrate_rpc_client::{ws_client, ChainApi};

let start = std::time::Instant::now();

let rpc = loop {
match ws_client(uri).await {
Ok(rpc) => break rpc,
Err(err) => {
if start.elapsed() > Duration::from_secs(timeout) {
return Err(format!("Connection timed out: {}", err));
}
}
}
tokio::time::sleep(Duration::from_secs(8)).await;
};

loop {
let result = ChainApi::<(), Hash, Header, ()>::block_hash(
&rpc,
Some(ListOrValue::Value(NumberOrHex::Number(block_number))),
)
.await;

match result {
Ok(ListOrValue::Value(Some(block_hash))) => break Ok(block_hash),
Err(err) => break Err(err.to_string()),
_ => {
if start.elapsed() > Duration::from_secs(timeout) {
break Err(String::from("Mining block timed out"));
}
}
}
tokio::time::sleep(Duration::from_secs(8)).await;
}
}

fn create_snapshot(ws_url: &str, snap_file: &PathBuf, at: Hash) -> tokio::process::Child {
Command::new(cargo_bin("try-runtime"))
.stdout(std::process::Stdio::piped())
Expand All @@ -69,8 +96,9 @@ async fn create_snapshot_works() {
.spawn()
.unwrap()
}

let block_number = 2;
let block_hash = common::block_hash(block_number, &ws_url).await.unwrap();
let block_hash = block_hash(block_number, &ws_url, 300).await.unwrap();

// Try to create a snapshot.
let child = create_snapshot(&ws_url, &snap_file_path, block_hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@ async fn execute_block_works() {
let port = 45789;
let ws_url = format!("ws://localhost:{}", port);

// Spawn a dev node.
let _ = std::thread::spawn(move || {
match common::start_node_inline(vec![
"--no-hardware-benchmarks",
"--dev",
format!("--rpc-port={}", port).as_str(),
]) {
Ok(_) => {}
Err(e) => {
panic!("Node exited with error: {}", e);
}
}
});
crate::start_dev_node(port);

// Wait some time to ensure the node is warmed up.
std::thread::sleep(Duration::from_secs(90));

Expand Down Expand Up @@ -75,7 +64,7 @@ async fn execute_block_works() {
// Assert that the block-execution process has executed the expected block.
assert!(matched.is_ok());

// Assert that the block-execution exited succesfully
// Assert that the block-execution exited successfully
assert!(block_execution
.wait_with_output()
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,8 @@ async fn follow_chain_works() {
let port = 45789;
let ws_url = format!("ws://localhost:{}", port);

// Spawn a dev node.
let _ = std::thread::spawn(move || {
match common::start_node_inline(vec![
"--no-hardware-benchmarks",
"--dev",
format!("--rpc-port={}", port).as_str(),
]) {
Ok(_) => {}
Err(e) => {
panic!("Node exited with error: {}", e);
}
}
});
crate::start_dev_node(port);

// Wait some time to ensure the node is warmed up.
std::thread::sleep(Duration::from_secs(90));

Expand Down
41 changes: 41 additions & 0 deletions core/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file is part of try-runtime-cli.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

mod create_snapshot;
mod execute_block;
mod follow_chain;
mod on_runtime_upgrade;

use std::sync::OnceLock;

fn start_dev_node(port: u32) {
static NODE: OnceLock<()> = OnceLock::new();
NODE.get_or_init(|| {
let _ = std::thread::spawn(move || {
match substrate_cli_test_utils::start_node_inline(vec![
"--no-hardware-benchmarks",
"--dev",
format!("--rpc-port={}", port).as_str(),
]) {
Ok(_) => {}
Err(e) => {
panic!("Node exited with error: {}", e);
}
}
});
});
}
File renamed without changes.
Loading