Stop proxy in controller tests to allow dir cleanup on Windows (#363)

* Stop wallet proxy in controller tests to allow directory cleanup in Windows

* Update test client

* Update to latest grin master

* is_unspent -> get_unspent
This commit is contained in:
jaspervdm 2020-03-10 12:00:33 +01:00 committed by GitHub
parent 1810854b24
commit 63eb25a92b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 63 additions and 15 deletions

16
Cargo.lock generated
View file

@ -854,7 +854,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "grin_api"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"easy-jsonrpc-mw 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -887,7 +887,7 @@ dependencies = [
[[package]]
name = "grin_chain"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"bit-vec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -910,7 +910,7 @@ dependencies = [
[[package]]
name = "grin_core"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -936,7 +936,7 @@ dependencies = [
[[package]]
name = "grin_keychain"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -958,7 +958,7 @@ dependencies = [
[[package]]
name = "grin_p2p"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
@ -979,7 +979,7 @@ dependencies = [
[[package]]
name = "grin_pool"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1012,7 +1012,7 @@ dependencies = [
[[package]]
name = "grin_store"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"croaring 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1032,7 +1032,7 @@ dependencies = [
[[package]]
name = "grin_util"
version = "4.0.0-alpha.1"
source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439"
source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555"
dependencies = [
"backtrace 0.3.44 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -25,6 +25,7 @@ use self::keychain::{ExtKeychain, Keychain};
use grin_wallet_libwallet as libwallet;
use impls::test_framework::{self, LocalWalletClient};
use libwallet::InitTxArgs;
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -37,6 +38,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
create_wallet_and_add!(
client1,
@ -258,6 +260,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -26,6 +26,7 @@ use grin_wallet_libwallet as libwallet;
use impls::test_framework::{self, LocalWalletClient};
use impls::{PathToSlate, SlatePutter as _};
use libwallet::{InitTxArgs, NodeClient};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
use util::ZeroingString;
@ -51,6 +52,7 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
@ -215,12 +217,12 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}
fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
setup(test_dir);
let seed_phrase = "affair pistol cancel crush garment candy ancient flag work \
market crush dry stand focus mutual weapon offer ceiling rival turn team spring \
where swift";
@ -229,6 +231,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
@ -752,6 +755,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}
@ -761,6 +765,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
fn output_scanning_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
create_wallet_and_add!(
@ -836,6 +841,9 @@ fn output_scanning_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
assert_eq!(outputs.2.len(), 16);
}
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -75,7 +75,10 @@ macro_rules! open_wallet_and_add {
};
}
pub fn clean_output_dir(test_dir: &str) {
let _ = fs::remove_dir_all(test_dir);
let path = std::path::Path::new(test_dir);
if path.is_dir() {
fs::remove_dir_all(test_dir).unwrap();
}
}
pub fn setup(test_dir: &str) {

View file

@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core;
use impls::test_framework::{self, LocalWalletClient};
use impls::{PathToSlate, SlateGetter as _, SlatePutter as _};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -38,6 +39,7 @@ fn file_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet::Erro
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
@ -215,6 +217,7 @@ fn file_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet::Erro
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core;
use impls::test_framework::{self, LocalWalletClient};
use libwallet::{InitTxArgs, IssueInvoiceTxArgs, Slate};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -34,6 +35,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
create_wallet_and_add!(
client1,
@ -201,6 +203,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
//bh += 3;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())

View file

@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core;
use grin_wallet_libwallet as libwallet;
use impls::test_framework::{self, LocalWalletClient};
use libwallet::{InitTxArgs, IssueInvoiceTxArgs, Slate};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -32,6 +33,7 @@ use common::{clean_output_dir, create_wallet_proxy, setup};
fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
create_wallet_and_add!(
client1,
@ -153,6 +155,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -21,6 +21,7 @@ extern crate grin_wallet_util;
use grin_wallet_libwallet as libwallet;
use impls::test_framework::{self, LocalWalletClient};
use libwallet::{InitTxArgs, Slate};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -35,6 +36,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
create_wallet_and_add!(
client1,
@ -157,6 +159,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -23,6 +23,7 @@ use grin_wallet_util::grin_core as core;
use self::libwallet::{InitTxArgs, Slate};
use impls::test_framework::{self, LocalWalletClient};
use impls::{PathToSlate, SlateGetter as _, SlatePutter as _};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -35,6 +36,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
@ -248,6 +250,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core;
use grin_wallet_libwallet as libwallet;
use impls::test_framework::{self, LocalWalletClient};
use libwallet::InitTxArgs;
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -34,6 +35,7 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
@ -130,6 +132,7 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -24,6 +24,7 @@ use self::core::core::transaction;
use self::core::global;
use self::libwallet::{InitTxArgs, OutputStatus, Slate};
use impls::test_framework::{self, LocalWalletClient};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -37,6 +38,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
create_wallet_and_add!(
client1,
@ -338,6 +340,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}
@ -348,6 +351,7 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
create_wallet_and_add!(
client1,
@ -515,6 +519,7 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> {
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -21,6 +21,7 @@ extern crate grin_wallet_util;
use grin_wallet_libwallet as libwallet;
use impls::test_framework::{self, LocalWalletClient};
use libwallet::{InitTxArgs, Slate, TxLogEntryType};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -33,6 +34,7 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
create_wallet_and_add!(
client1,
@ -167,6 +169,7 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

View file

@ -23,6 +23,7 @@ extern crate grin_wallet_libwallet as libwallet;
// use grin_wallet_util::grin_core as core;
use impls::test_framework::{self, LocalWalletClient};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
@ -35,6 +36,7 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
@ -101,6 +103,7 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
assert_eq!(messages.len(), 32);
owner_api.stop_updater()?;
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_secs(2));
Ok(())
}

View file

@ -43,7 +43,7 @@ fn get_output_local(chain: &chain::Chain, commit: &pedersen::Commitment) -> Opti
];
for x in outputs.iter() {
if chain.is_unspent(&x).is_ok() {
if chain.get_unspent(&x).unwrap().is_some() {
let block_height = chain.get_header_for_output(&x).unwrap().height;
let output_pos = chain.get_output_pos(&x.commit).unwrap_or(0);
return Some(api::Output::new(&commit, block_height, output_pos));

View file

@ -139,8 +139,16 @@ where
self.running.store(true, Ordering::Relaxed);
loop {
thread::sleep(Duration::from_millis(10));
if !self.running.load(Ordering::Relaxed) {
info!("Proxy stopped");
return Ok(());
}
// read queue
let m = self.rx.recv().unwrap();
let m = match self.rx.recv_timeout(Duration::from_millis(10)) {
Ok(m) => m,
Err(_) => continue,
};
trace!("Wallet Client Proxy Received: {:?}", m);
let resp = match m.method.as_ref() {
"get_chain_tip" => self.get_chain_tip(m)?,
@ -154,9 +162,6 @@ where
};
self.respond(resp);
if !self.running.load(Ordering::Relaxed) {
return Ok(());
}
}
}