Skip to content
Snippets Groups Projects
Commit 8674e6e8 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

fix(!116): remove notify lib for end2end tests

parent dabb2c09
No related branches found
No related tags found
No related merge requests found
Pipeline #32266 passed
...@@ -16,7 +16,6 @@ ctrlc = "3.2.2" ...@@ -16,7 +16,6 @@ ctrlc = "3.2.2"
cucumber = "0.11" cucumber = "0.11"
env_logger = "0.9.0" env_logger = "0.9.0"
hex = "0.4" hex = "0.4"
notify = "4.0"
parity-scale-codec = "3.1.5" parity-scale-codec = "3.1.5"
portpicker = "0.1.1" portpicker = "0.1.1"
serde_json = "1.0.64" serde_json = "1.0.64"
......
...@@ -32,9 +32,10 @@ use parity_scale_codec::Encode; ...@@ -32,9 +32,10 @@ use parity_scale_codec::Encode;
use serde_json::Value; use serde_json::Value;
use sp_keyring::AccountKeyring; use sp_keyring::AccountKeyring;
use std::io::prelude::*; use std::io::prelude::*;
use std::path::PathBuf; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::str::FromStr; use std::str::FromStr;
use std::time::{Duration, Instant};
use subxt::ext::{sp_core, sp_runtime}; use subxt::ext::{sp_core, sp_runtime};
use subxt::rpc::rpc_params; use subxt::rpc::rpc_params;
use subxt::tx::BaseExtrinsicParamsBuilder; use subxt::tx::BaseExtrinsicParamsBuilder;
...@@ -218,34 +219,30 @@ fn spawn_full_node( ...@@ -218,34 +219,30 @@ fn spawn_full_node(
} }
} }
fn wait_until_log_line(expected_log_line: &str, log_file_path: &str, timeout: std::time::Duration) { fn wait_until_log_line(expected_log_line: &str, log_file_path: &str, timeout: Duration) {
let (tx, rx) = std::sync::mpsc::channel(); let start = Instant::now();
let mut watcher = notify::watcher(tx, std::time::Duration::from_millis(100)).unwrap();
use notify::Watcher as _;
watcher
.watch(log_file_path, notify::RecursiveMode::NonRecursive)
.unwrap();
let mut pos = 0;
loop { loop {
match rx.recv_timeout(timeout) { let now = Instant::now();
Ok(notify::DebouncedEvent::Write(_)) => { if now.duration_since(start) > timeout {
let mut file = std::fs::File::open(log_file_path).unwrap(); eprintln!("Timeout starting node");
file.seek(std::io::SeekFrom::Start(pos)).unwrap(); std::process::exit(1);
pos = file.metadata().unwrap().len(); }
let reader = std::io::BufReader::new(file); if has_log_line(log_file_path, expected_log_line) {
// Ready
for line in reader.lines() { return;
if line.expect("fail to read line").contains(expected_log_line) { }
return; std::thread::sleep(Duration::from_millis(100));
} }
} }
}
Ok(_) => {} fn has_log_line(log_file_path: &str, expected_log_line: &str) -> bool {
Err(err) => { let mut file = std::fs::File::open(log_file_path).unwrap();
eprintln!("Error: {:?}", err); file.seek(std::io::SeekFrom::Start(0)).unwrap();
std::process::exit(1); let reader = std::io::BufReader::new(file);
} for line in reader.lines() {
if line.expect("fail to read line").contains(expected_log_line) {
return true;
} }
} }
false
} }
...@@ -472,6 +472,15 @@ struct CustomOpts { ...@@ -472,6 +472,15 @@ struct CustomOpts {
/// Keep running /// Keep running
#[clap(short, long)] #[clap(short, long)]
keep_running: bool, keep_running: bool,
/// For compliance with Jetbrains IDE which pushes extra args.
/// https://youtrack.jetbrains.com/issue/CPP-33071/cargo-test-adds-extra-options-which-conflict-with-Cucumber
#[clap(short, long)]
format: Option<String>,
#[clap(short, long = "show-output")]
show_output: bool,
#[clap(short = 'Z', long)]
z: Option<String>,
} }
const DOCKER_FEATURES_PATH: &str = "/var/lib/duniter/cucumber-features"; const DOCKER_FEATURES_PATH: &str = "/var/lib/duniter/cucumber-features";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment