fix stdout issue with test framework for cached data tests
This commit is contained in:
parent
0f51891359
commit
17fdbe941b
|
@ -1,3 +1,5 @@
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
#[cfg(any(test, feature = "proptest-impl"))]
|
#[cfg(any(test, feature = "proptest-impl"))]
|
||||||
use proptest_derive::Arbitrary;
|
use proptest_derive::Arbitrary;
|
||||||
|
|
||||||
|
@ -11,6 +13,15 @@ pub enum Network {
|
||||||
Testnet,
|
Testnet,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Network {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Network::Mainnet => f.write_str("Mainnet"),
|
||||||
|
Network::Testnet => f.write_str("Testnet"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Network {
|
impl Network {
|
||||||
/// Get the default port associated to this network.
|
/// Get the default port associated to this network.
|
||||||
pub fn default_port(&self) -> u16 {
|
pub fn default_port(&self) -> u16 {
|
||||||
|
|
|
@ -86,6 +86,7 @@ impl CommandExt for Command {
|
||||||
dir,
|
dir,
|
||||||
deadline: None,
|
deadline: None,
|
||||||
stdout: None,
|
stdout: None,
|
||||||
|
bypass_test_stdout: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +153,7 @@ pub struct TestChild<T> {
|
||||||
pub child: Child,
|
pub child: Child,
|
||||||
pub stdout: Option<Lines<BufReader<ChildStdout>>>,
|
pub stdout: Option<Lines<BufReader<ChildStdout>>>,
|
||||||
pub deadline: Option<Instant>,
|
pub deadline: Option<Instant>,
|
||||||
|
bypass_test_stdout: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> TestChild<T> {
|
impl<T> TestChild<T> {
|
||||||
|
@ -190,6 +192,13 @@ impl<T> TestChild<T> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configures testrunner to forward stdout to the true stdout rather than
|
||||||
|
/// fakestdout used by cargo tests.
|
||||||
|
pub fn bypass_test_stdout(mut self, cond: bool) -> Self {
|
||||||
|
self.bypass_test_stdout = cond;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks each line of the child's stdout against `regex`, and returns matching lines.
|
/// Checks each line of the child's stdout against `regex`, and returns matching lines.
|
||||||
///
|
///
|
||||||
/// Kills the child after the configured timeout has elapsed.
|
/// Kills the child after the configured timeout has elapsed.
|
||||||
|
@ -221,7 +230,13 @@ impl<T> TestChild<T> {
|
||||||
// since we're about to discard this line write it to stdout so our
|
// since we're about to discard this line write it to stdout so our
|
||||||
// test runner can capture it and display if the test fails, may
|
// test runner can capture it and display if the test fails, may
|
||||||
// cause weird reordering for stdout / stderr
|
// cause weird reordering for stdout / stderr
|
||||||
println!("{}", line);
|
if !self.bypass_test_stdout {
|
||||||
|
println!("{}", line);
|
||||||
|
} else {
|
||||||
|
use std::io::Write;
|
||||||
|
#[allow(clippy::explicit_write)]
|
||||||
|
writeln!(std::io::stdout(), "{}", line).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
if re.is_match(&line) {
|
if re.is_match(&line) {
|
||||||
self.stdout = Some(lines);
|
self.stdout = Some(lines);
|
||||||
|
|
|
@ -652,7 +652,6 @@ fn cached_sapling_test_config() -> Result<ZebradConfig> {
|
||||||
config.consensus.checkpoint_sync = true;
|
config.consensus.checkpoint_sync = true;
|
||||||
config.state.cache_dir = "/zebrad-cache".into();
|
config.state.cache_dir = "/zebrad-cache".into();
|
||||||
config.state.memory_cache_bytes = 52428800;
|
config.state.memory_cache_bytes = 52428800;
|
||||||
config.tracing.endpoint_addr = Some("0.0.0.0:3000".parse().unwrap());
|
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,15 +665,17 @@ fn create_cached_database_height(network: Network, height: Height) -> Result<()>
|
||||||
// TODO: add convenience methods?
|
// TODO: add convenience methods?
|
||||||
config.network.network = network;
|
config.network.network = network;
|
||||||
config.state.debug_stop_at_height = Some(height.0);
|
config.state.debug_stop_at_height = Some(height.0);
|
||||||
let dir = PathBuf::from("/");
|
let dir = PathBuf::from("/zebrad-cache");
|
||||||
|
|
||||||
fs::File::create(dir.join("zebrad.toml"))?.write_all(toml::to_string(&config)?.as_bytes())?;
|
fs::File::create(dir.join("zebrad.toml"))?.write_all(toml::to_string(&config)?.as_bytes())?;
|
||||||
|
|
||||||
let mut child = dir.spawn_child(&["start"])?.with_timeout(timeout);
|
let mut child = dir
|
||||||
|
.spawn_child(&["start"])?
|
||||||
|
.with_timeout(timeout)
|
||||||
|
.bypass_test_stdout(true);
|
||||||
|
|
||||||
// TODO: is there a way to check for testnet or mainnet here?
|
let network = format!("network: {},", network);
|
||||||
// For example: "network=Mainnet" or "network=Testnet"
|
child.expect_stdout(&network)?;
|
||||||
child.expect_stdout("network: Mainnet,")?;
|
|
||||||
child.expect_stdout(STOP_AT_HEIGHT_REGEX)?;
|
child.expect_stdout(STOP_AT_HEIGHT_REGEX)?;
|
||||||
child.kill()?;
|
child.kill()?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue