Skip to content

Commit

Permalink
fix(rust): allow bats tests to run concurrently for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre committed Nov 29, 2023
1 parent e7af5a1 commit 1a34228
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
10 changes: 5 additions & 5 deletions implementations/rust/ockam/ockam_command/src/authority/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use std::process;

use clap::ArgGroup;
use clap::Args;
use miette::{IntoDiagnostic, miette};
use miette::{miette, IntoDiagnostic};
use serde::{Deserialize, Serialize};

use ockam::Context;
use ockam::identity::{AttributesEntry, Identifier};
use ockam::Context;
use ockam_api::authority_node;
use ockam_api::authority_node::{OktaConfiguration, TrustedIdentity};
use ockam_api::bootstrapped_identities_store::PreTrustedIdentities;
Expand All @@ -17,11 +17,11 @@ use ockam_api::nodes::service::default_address::DefaultAddress;
use ockam_core::compat::collections::HashMap;
use ockam_core::compat::fmt;

use crate::{CommandGlobalOpts, docs, Result};
use crate::node::util::run_ockam;
use crate::util::parsers::internet_address_parser;
use crate::util::{embedded_node_that_is_not_stopped, exitcode};
use crate::util::{local_cmd, node_rpc};
use crate::util::parsers::internet_address_parser;
use crate::{docs, CommandGlobalOpts, Result};

const LONG_ABOUT: &str = include_str!("./static/create/long_about.txt");
const PREVIEW_TAG: &str = include_str!("../static/preview_tag.txt");
Expand Down Expand Up @@ -317,7 +317,7 @@ fn parse_trusted_identities(values: &str) -> Result<TrustedIdentities> {

#[cfg(test)]
mod tests {
use ockam::identity::{Identifier, identities};
use ockam::identity::{identities, Identifier};
use ockam_core::compat::collections::HashMap;

use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct ShowNodeResponse {
pub is_default: bool,
pub name: String,
pub is_up: bool,
pub node_pid: Option<u32>,
pub route: RouteToNode,
#[serde(skip_serializing_if = "Option::is_none")]
pub identity: Option<String>,
Expand All @@ -46,6 +47,7 @@ impl ShowNodeResponse {
name: &str,
is_up: bool,
node_port: Option<u16>,
node_pid: Option<u32>,
) -> ShowNodeResponse {
let mut m = MultiAddr::default();
let short = m.push_back(Node::new(name)).ok().map(|_| m);
Expand All @@ -64,6 +66,7 @@ impl ShowNodeResponse {
is_default,
name: name.to_owned(),
is_up,
node_pid,
route: RouteToNode { short, verbose },
identity: None,
transports: Default::default(),
Expand Down Expand Up @@ -94,6 +97,10 @@ impl Display for ShowNodeResponse {
}
)?;

if let Some(node_pid) = self.node_pid {
writeln!(buffer, " PID: {}", node_pid)?;
}

writeln!(buffer, " Route To Node:")?;
if let Some(short) = &self.route.short {
writeln!(buffer, " Short: {short}")?;
Expand Down
2 changes: 2 additions & 0 deletions implementations/rust/ockam/ockam_command/src/node/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ pub async fn print_query_status(
&node_name,
is_authority_node,
node_info.tcp_listener_port(),
node_info.pid(),
)
} else {
let mut show_node = ShowNodeResponse::new(
node_info.is_default(),
&node_name,
true,
node_info.tcp_listener_port(),
node_info.pid(),
);
// Get list of services for the node
let services: ServiceList = node.ask(ctx, api::list_services()).await?;
Expand Down
14 changes: 13 additions & 1 deletion implementations/rust/ockam/ockam_command/tests/bats/nodes.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ teardown() {
# ===== UTILS

force_kill_node() {
run killall ockam
max_retries=5
i=0
while [[ $i -lt $max_retries ]]; do
pid="$($OCKAM node show $1 --output json | jq .node_pid)"
run kill -9 $pid
# Killing a node created without `-f` leaves the
# process in a defunct state when running within Docker.
if ! ps -p $pid || ps -p $pid | grep defunct; then
return
fi
sleep 0.2
((i = i + 1))
done
}

# ===== TESTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ use core::str::FromStr;

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

use ockam_core::{Error, Result};
use ockam_core::compat::{string::String, vec::Vec};
use ockam_core::env::FromString;
use ockam_core::{Error, Result};

use crate::models::{ChangeHash, CHANGE_HASH_LEN, IDENTIFIER_LEN};
use crate::{Identifier, IdentityError};
use crate::models::{CHANGE_HASH_LEN, ChangeHash, IDENTIFIER_LEN};

impl Serialize for Identifier {
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
S: Serializer,
where
S: Serializer,
{
serializer.serialize_str(&String::from(self))
}
}

impl<'de> Deserialize<'de> for Identifier {
fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
where
D: Deserializer<'de>,
where
D: Deserializer<'de>,
{
let str: String = Deserialize::deserialize(deserializer)?;

Expand Down Expand Up @@ -198,7 +198,7 @@ impl AsRef<[u8]> for ChangeHash {

#[cfg(test)]
mod test {
use quickcheck::{Arbitrary, Gen, quickcheck};
use quickcheck::{quickcheck, Arbitrary, Gen};

use super::*;

Expand Down

0 comments on commit 1a34228

Please sign in to comment.