Skip to content

Commit

Permalink
chore: test fixing cucumber on ci (#6491)
Browse files Browse the repository at this point in the history
Description
---

Motivation and Context
---

How Has This Been Tested?
---

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

<!-- 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
SWvheerden authored Aug 29, 2024
1 parent 7cb88fa commit 3c5ac45
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
19 changes: 16 additions & 3 deletions integration_tests/src/base_node_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{
convert::TryInto,
fmt::{Debug, Formatter},
net::TcpListener,
path::PathBuf,
str::FromStr,
sync::Arc,
Expand Down Expand Up @@ -106,11 +108,10 @@ pub async fn spawn_base_node_with_config(

base_node_identity = node_ps.identity.clone();
} else {
// each spawned wallet will use different ports
// each spawned base node will use different ports
port = get_port(18000..18499).unwrap();
grpc_port = get_port(18500..18999).unwrap();
// create a new temporary directory
// temp_dir_path = tempdir().unwrap().path().to_path_buf();
temp_dir_path = world
.current_base_dir
.as_ref()
Expand Down Expand Up @@ -228,7 +229,7 @@ pub async fn spawn_base_node_with_config(
GrpcMethod::GetSideChainUtxos,
];

// Heirachically set the base path for all configs
// Hierarchically set the base path for all configs
base_node_config.base_node.set_base_path(temp_dir_path.clone());

println!(
Expand Down Expand Up @@ -259,5 +260,17 @@ impl BaseNodeProcess {

pub fn kill(&mut self) {
self.kill_signal.trigger();
loop {
// lets wait till the port is cleared
if TcpListener::bind(("127.0.0.1", self.port.try_into().unwrap())).is_ok() {
break;
}
}
loop {
// lets wait till the port is cleared
if TcpListener::bind(("127.0.0.1", self.grpc_port.try_into().unwrap())).is_ok() {
break;
}
}
}
}
2 changes: 1 addition & 1 deletion integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn get_base_dir() -> PathBuf {
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
let max_tries = 40;
let max_tries = 4 * 60;
let mut attempts = 0;

loop {
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/src/wallet_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn spawn_wallet(
let port: u64;
let grpc_port: u64;
let temp_dir_path: PathBuf;
let wallet_config: WalletConfig;
let mut wallet_config: WalletConfig;

if let Some(wallet_ps) = world.wallets.get(&wallet_name) {
port = wallet_ps.port;
Expand All @@ -91,6 +91,9 @@ pub async fn spawn_wallet(
.join(format!("{}_grpc_port_{}", wallet_name.clone(), grpc_port));

wallet_config = WalletConfig::default();
wallet_config
.base_node_service_config
.base_node_monitor_max_refresh_interval = Duration::from_secs(5);
};

let base_node = base_node_name.map(|name| {
Expand Down
18 changes: 0 additions & 18 deletions integration_tests/tests/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::{
fs,
io,
path::PathBuf,
process,
str::{self},
sync::{Arc, Mutex},
};
Expand Down Expand Up @@ -70,11 +69,6 @@ fn main() {
.repeat_failed()
// following config needed to use eprint statements in the tests
.max_concurrent_scenarios(5)
//.with_writer(
// writer::Basic::raw(io::stdout(), writer::Coloring::Never, 0)
// .summarized()
// .assert_normalized(),
//)
.after(move |_feature, _rule, scenario, ev, maybe_world| {
let stdout_buffer = stdout_buffer_clone.clone();
Box::pin(async move {
Expand Down Expand Up @@ -118,16 +112,4 @@ fn main() {

// If by any chance we have anything in the stdout buffer just log it.
flush_stdout(&stdout_buffer);

// Move the logs to the temp dir
let crate_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let log_dir = crate_root.join("log");
let test_run_dir = crate_root.join(format!("tests/temp/cucumber_{}/logs", process::id()));
fs::create_dir_all(&test_run_dir).unwrap();

for entry in fs::read_dir(log_dir).unwrap() {
let file = entry.unwrap();
fs::copy(file.path(), test_run_dir.join(file.file_name())).unwrap();
fs::remove_file(file.path()).unwrap();
}
}
3 changes: 2 additions & 1 deletion integration_tests/tests/features/Sync.feature
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ Feature: Block Sync
When mining node MINER2 mines <Y1> blocks with min difficulty 1 and max difficulty 2
Then node SYNCER is at the same height as node SEED

@critical
# works locally but fails on CI, fails on the step to start a node
@critical @broken
Examples:
| X1 | Y1 |
| 101 | 10 |
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/features/WalletFFI.feature
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Feature: Wallet FFI
Given I have a seed node SEED
When I have a base node BASE1 connected to all seed nodes
When I have wallet SENDER connected to base node BASE1
And I have a ffi wallet FFI_WALLET connected to base node SEED
And I have a ffi wallet FFI_WALLET connected to base node BASE1
When I have wallet RECEIVER connected to base node BASE1

# Force some P2P discovery with contact liveness
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/tests/steps/node_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ async fn node_pending_connection_to(world: &mut TariWorld, first_node: String, s
#[when(expr = "I wait for {word} to have {int} connections")]
async fn wait_for_node_have_x_connections(world: &mut TariWorld, node: String, num_connections: usize) {
let mut node_client = world.get_base_node_or_wallet_client(&node).await.unwrap();

let mut connected_peers = 0;
for _i in 0..100 {
let res = match node_client {
NodeClient::Wallet(ref mut client) => client.list_connected_peers(Empty {}).await.unwrap(),
NodeClient::BaseNode(ref mut client) => client.list_connected_peers(Empty {}).await.unwrap(),
};
let res = res.into_inner();

connected_peers = res.connected_peers.len();
if res.connected_peers.len() >= num_connections {
return;
}
tokio::time::sleep(Duration::from_secs(1)).await;
}

panic!("Peer was not connected in time");
panic!("Peer was not connected in time, connected to {} peers", connected_peers);
}

#[then(expr = "all nodes are on the same chain at height {int}")]
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/steps/wallet_ffi_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ async fn ffi_detects_transaction(
if found_count >= count {
break;
}
tokio::time::sleep(Duration::from_secs(1)).await;
tokio::time::sleep(Duration::from_secs(5)).await;
}
println!("Counters {:?}", ffi_wallet.get_counters());
match comparison.as_str() {
Expand Down
6 changes: 4 additions & 2 deletions integration_tests/tests/steps/wallet_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ async fn wallet_has_at_least_num_txs(world: &mut TariWorld, wallet: String, num_

let num_retries = 100;
let mut current_status = 0;
let mut total_found = 0;

for _ in 0..num_retries {
let mut txs = client
Expand All @@ -554,12 +555,13 @@ async fn wallet_has_at_least_num_txs(world: &mut TariWorld, wallet: String, num_
if found_tx >= num_txs {
return;
}
total_found += found_tx;
tokio::time::sleep(Duration::from_secs(5)).await;
}

panic!(
"Wallet {} failed to have at least num {} txs with status {}, current status is {}",
wallet, num_txs, transaction_status, current_status
"Wallet {} failed to have at least num {} txs with status {}, current status is {}, scanned txs {}",
wallet, num_txs, transaction_status, current_status, total_found
);
}

Expand Down

0 comments on commit 3c5ac45

Please sign in to comment.