From ab879fcfc232bb3123845284bc65b434e414ceb9 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 29 Sep 2022 13:48:52 -0700 Subject: [PATCH] Make index::custom_index_size test faster (#579) --- tests/command_builder.rs | 4 +++- tests/index.rs | 20 ++++++++++++++------ tests/lib.rs | 1 - tests/range.rs | 16 ++++++++-------- tests/state.rs | 12 ------------ 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/tests/command_builder.rs b/tests/command_builder.rs index 921a7be015..016488fb99 100644 --- a/tests/command_builder.rs +++ b/tests/command_builder.rs @@ -63,7 +63,7 @@ impl CommandBuilder { } } - pub(crate) fn run(self) { + pub(crate) fn run(self) -> TempDir { let mut command = Command::new(executable_path("ord")); if let Some(rpc_server_url) = self.rpc_server_url { @@ -99,5 +99,7 @@ impl CommandBuilder { self.expected_stderr.assert_match(stderr); self.expected_stdout.assert_match(stdout); + + self.tempdir } } diff --git a/tests/index.rs b/tests/index.rs index 7b51ccbd35..e37f89147a 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -2,15 +2,23 @@ use super::*; #[test] fn custom_index_size() { - let state = SlowTest::new() - .command("--max-index-size 1mib find 0") + let rpc_server = test_bitcoincore_rpc::spawn(); + rpc_server.mine_blocks(1); + + let tempdir = CommandBuilder::new("--max-index-size 1mib find 0") + .rpc_server(&rpc_server) .expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:0\n") - .blocks(1) - .output(); + .run(); assert_eq!( - state - .ord_data_dir() + tempdir + .path() + .join(if cfg!(target_os = "macos") { + "Library/Application Support/" + } else { + ".local/share" + }) + .join("ord") .join("index.redb") .metadata() .unwrap() diff --git a/tests/lib.rs b/tests/lib.rs index 6321d0cf40..8ed7fa4baa 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -24,7 +24,6 @@ use { std::{ fs, net::TcpListener, - path::PathBuf, process::{Child, Command, Stdio}, str, sync::Once, diff --git a/tests/range.rs b/tests/range.rs index 16bd0fc005..03665ac661 100644 --- a/tests/range.rs +++ b/tests/range.rs @@ -4,54 +4,54 @@ use super::*; fn genesis() { CommandBuilder::new("range 0") .expected_stdout("[0,5000000000)\n") - .run() + .run(); } #[test] fn second_block() { CommandBuilder::new("range 1") .expected_stdout("[5000000000,10000000000)\n") - .run() + .run(); } #[test] fn last_block_with_subsidy() { CommandBuilder::new("range 6929999") .expected_stdout("[2099999997689999,2099999997690000)\n") - .run() + .run(); } #[test] fn first_block_without_subsidy() { CommandBuilder::new("range 6930000") .expected_stdout("[2099999997690000,2099999997690000)\n") - .run() + .run(); } #[test] fn genesis_names() { CommandBuilder::new("range --name 0") .expected_stdout("[nvtdijuwxlp,nvtcsezkbth)\n") - .run() + .run(); } #[test] fn names_before_last() { CommandBuilder::new("range --name 6929998") .expected_stdout("[b,a)\n") - .run() + .run(); } #[test] fn last_name() { CommandBuilder::new("range --name 6929999") .expected_stdout("[a,)\n") - .run() + .run(); } #[test] fn block_with_no_subsidy_range() { CommandBuilder::new("range --name 6930000") .expected_stdout("[,)\n") - .run() + .run(); } diff --git a/tests/state.rs b/tests/state.rs index b150632b23..6a79b1c987 100644 --- a/tests/state.rs +++ b/tests/state.rs @@ -198,18 +198,6 @@ impl State { tx } - - pub(crate) fn ord_data_dir(&self) -> PathBuf { - self - .tempdir - .path() - .join(if cfg!(target_os = "macos") { - "Library/Application Support/" - } else { - ".local/share" - }) - .join("ord") - } } impl Drop for State {