Skip to content

Commit

Permalink
test: fix wallet ffi base dirs in tests to prevent ci from returning …
Browse files Browse the repository at this point in the history
…false failures (#5418)

Description
---
The wallet ffi started using the log directory for it's data directory.
This conflicted with the new code to move logs into the test run dir.

Motivation and Context
---
CI was passing and reporting failure.

How Has This Been Tested?
---
Locally

What process can a PR reviewer use to test or verify this change?
---
Watch CI pass

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
brianp authored May 30, 2023
1 parent 1770946 commit c29ab15
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 36 deletions.
8 changes: 1 addition & 7 deletions integration_tests/src/base_node_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::{
default::Default,
fmt::{Debug, Formatter},
path::PathBuf,
process,
str::FromStr,
sync::Arc,
time::Duration,
Expand All @@ -42,7 +41,7 @@ use tari_shutdown::Shutdown;
use tokio::task;
use tonic::transport::Channel;

use crate::{get_peer_addresses, get_port, wait_for_service, TariWorld};
use crate::{get_base_dir, get_peer_addresses, get_port, wait_for_service, TariWorld};

#[derive(Clone)]
pub struct BaseNodeProcess {
Expand Down Expand Up @@ -81,11 +80,6 @@ pub async fn spawn_base_node(world: &mut TariWorld, is_seed_node: bool, bn_name:
spawn_base_node_with_config(world, is_seed_node, bn_name, peers, BaseNodeConfig::default()).await;
}

pub fn get_base_dir() -> PathBuf {
let crate_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
crate_root.join(format!("tests/temp/cucumber_{}", process::id()))
}

pub async fn spawn_base_node_with_config(
world: &mut TariWorld,
is_seed_node: bool,
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/chat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tari_comms::{
use tari_comms_dht::{store_forward::SafConfig, DbConnectionUrl, DhtConfig, NetworkDiscoveryConfig};
use tari_p2p::{P2pConfig, TcpTransportConfig, TransportConfig};

use crate::{base_node_process::get_base_dir, get_port};
use crate::{get_base_dir, get_port};

pub async fn spawn_chat_client(name: &str, seed_peers: Vec<Peer>) -> Client {
let port = get_port(18000..18499).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/chat_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use tari_contacts::contacts_service::{service::ContactOnlineStatus, types::Messa
use tari_p2p::{P2pConfig, TcpTransportConfig, TransportConfig};
use tari_utilities::message_format::MessageFormat;

use crate::{base_node_process::get_base_dir, get_port};
use crate::{get_base_dir, get_port};

#[cfg_attr(windows, link(name = "tari_chat_ffi.dll"))]
#[cfg_attr(not(windows), link(name = "tari_chat_ffi"))]
Expand Down
7 changes: 6 additions & 1 deletion integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{net::TcpListener, ops::Range, time::Duration};
use std::{net::TcpListener, ops::Range, path::PathBuf, process, time::Duration};

use rand::Rng;

Expand Down Expand Up @@ -51,6 +51,11 @@ pub fn get_port(range: Range<u16>) -> Option<u64> {
}
}

pub fn get_base_dir() -> PathBuf {
let crate_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
crate_root.join(format!("tests/temp/cucumber_{}", process::id()))
}

pub async fn wait_for_service(port: u64) {
// The idea is that if the port is taken it means the service is running.
// If the port is not taken the service hasn't come up yet
Expand Down
46 changes: 27 additions & 19 deletions integration_tests/src/wallet_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@ use indexmap::IndexMap;
use libc::c_void;

// use tari_wallet_ffi::*;
use super::{
ffi::{
Balance,
Callbacks,
CompletedTransactions,
Contact,
Contacts,
ContactsLivenessData,
FeePerGramStats,
PendingInboundTransactions,
PendingOutboundTransactions,
PublicKeys,
WalletAddress,
},
get_port,
use super::ffi::{
Balance,
Callbacks,
CompletedTransactions,
Contact,
Contacts,
ContactsLivenessData,
FeePerGramStats,
PendingInboundTransactions,
PendingOutboundTransactions,
PublicKeys,
WalletAddress,
};
use crate::{
ffi::{self},
get_base_dir,
get_port,
TariWorld,
};

Expand All @@ -67,10 +66,19 @@ impl WalletFFI {
let port = get_port(18000..18499).unwrap();
let transport_config =
ffi::TransportConfig::create_tcp(CString::new(format!("/ip4/127.0.0.1/tcp/{}", port)).unwrap().into_raw());
let now: DateTime<Utc> = SystemTime::now().into();
let base_dir = format!("./log/ffi_wallets/{}", now.format("%Y%m%d-%H%M%S"));
let comms_config = ffi::CommsConfig::create(port, transport_config, base_dir.clone());
let log_path = format!("{}/log/ffi_wallet.log", base_dir);
let base_dir_path = get_base_dir()
.join("ffi_wallets")
.join(format!("port_{}", port))
.join(name.clone());
let base_dir: String = base_dir_path.as_os_str().to_str().unwrap().into();
let comms_config = ffi::CommsConfig::create(port, transport_config, base_dir);
let log_path = base_dir_path
.join("logs")
.join("ffi_wallet.log")
.as_os_str()
.to_str()
.unwrap()
.into();
let wallet = ffi::Wallet::create(comms_config, log_path, seed_words_ptr);
Self { name, port, wallet }
}
Expand Down
9 changes: 2 additions & 7 deletions integration_tests/src/wallet_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{path::PathBuf, process, str::FromStr, thread, time::Duration};
use std::{path::PathBuf, str::FromStr, thread, time::Duration};

use tari_app_grpc::tari_rpc::SetBaseNodeRequest;
use tari_app_utilities::common_cli_args::CommonCliArgs;
Expand All @@ -35,7 +35,7 @@ use tari_wallet_grpc_client::WalletGrpcClient;
use tokio::runtime;
use tonic::transport::Channel;

use crate::{get_peer_addresses, get_port, wait_for_service, TariWorld};
use crate::{get_base_dir, get_peer_addresses, get_port, wait_for_service, TariWorld};

#[derive(Clone, Debug)]
pub struct WalletProcess {
Expand Down Expand Up @@ -246,8 +246,3 @@ impl WalletProcess {
self.kill_signal.trigger();
}
}

pub fn get_base_dir() -> PathBuf {
let crate_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
crate_root.join(format!("tests/temp/cucumber_{}", process::id()))
}

0 comments on commit c29ab15

Please sign in to comment.