Skip to content

Commit

Permalink
changes from feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pepoviola committed Nov 9, 2023
1 parent 1b907e1 commit aa7f6de
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
11 changes: 6 additions & 5 deletions crates/orchestrator/src/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ where
node.rpc_port.drop_listener();
node.prometheus_port.drop_listener();

let err_context = format!(
"Failed to spawn node: {} with opts: {:#?}",
node.name, spawn_ops
);
let running_node = ctx.ns.spawn_node(spawn_ops).await.context(err_context)?;
let running_node = ctx.ns.spawn_node(&spawn_ops).await.with_context(|| {
format!(
"Failed to spawn node: {} with opts: {:#?}",
node.name, spawn_ops
)
})?;

let ws_uri = format!("ws://{}:{}", LOCALHOST, node.rpc_port.0);
let prometheus_uri = format!("http://{}:{}/metrics", LOCALHOST, node.prometheus_port.0);
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub trait ProviderNamespace {

async fn nodes(&self) -> HashMap<String, DynNode>;

async fn spawn_node(&self, options: SpawnNodeOptions) -> Result<DynNode, ProviderError>;
async fn spawn_node(&self, options: &SpawnNodeOptions) -> Result<DynNode, ProviderError>;

async fn generate_files(&self, options: GenerateFilesOptions) -> Result<(), ProviderError>;

Expand Down
26 changes: 13 additions & 13 deletions crates/provider/src/native/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ where
.collect()
}

async fn spawn_node(&self, options: SpawnNodeOptions) -> Result<DynNode, ProviderError> {
async fn spawn_node(&self, options: &SpawnNodeOptions) -> Result<DynNode, ProviderError> {
let mut inner = self.inner.write().await;

if inner.nodes.contains_key(&options.name) {
return Err(ProviderError::DuplicatedNodeName(options.name));
return Err(ProviderError::DuplicatedNodeName(options.name.clone()));
}

// create node directories and filepaths
Expand Down Expand Up @@ -143,9 +143,9 @@ where
// create node structure holding state
let node = NativeNode {
name: options.name.clone(),
program: options.program,
args: options.args,
env: options.env,
program: options.program.clone(),
args: options.args.clone(),
env: options.env.clone(),
base_dir,
config_dir,
data_dir,
Expand All @@ -165,15 +165,15 @@ where
};

// store node inside namespace
inner.nodes.insert(options.name, node.clone());
inner.nodes.insert(options.name.clone(), node.clone());

Ok(Arc::new(node))
}

async fn generate_files(&self, options: GenerateFilesOptions) -> Result<(), ProviderError> {
// we spawn a node doing nothing but looping so we can execute our commands
let temp_node = self
.spawn_node(SpawnNodeOptions {
.spawn_node(&SpawnNodeOptions {
name: format!("temp_{}", Uuid::new_v4()),
program: "bash".to_string(),
args: vec!["-c".to_string(), "while :; do sleep 1; done".to_string()],
Expand Down Expand Up @@ -288,7 +288,7 @@ mod tests {

let node = namespace
.spawn_node(
SpawnNodeOptions::new("mynode", "/path/to/my/node_binary")
&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary")
.args(vec![
"-flag1",
"--flag2",
Expand Down Expand Up @@ -452,12 +452,12 @@ mod tests {
let namespace = provider.create_namespace().await.unwrap();

namespace
.spawn_node(SpawnNodeOptions::new("mynode", "./testing/dummy_node"))
.spawn_node(&SpawnNodeOptions::new("mynode", "./testing/dummy_node"))
.await
.unwrap();

let result = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "./testing/dummy_node"))
.spawn_node(&SpawnNodeOptions::new("mynode", "./testing/dummy_node"))
.await;

// we must match here because Arc<dyn Node + Send + Sync> doesn't implements Debug, so unwrap_err is not an option
Expand All @@ -481,7 +481,7 @@ mod tests {
pm.spawn_should_error(std::io::ErrorKind::TimedOut).await;

let result = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "./testing/dummy_node"))
.spawn_node(&SpawnNodeOptions::new("mynode", "./testing/dummy_node"))
.await;

// we must match here because Arc<dyn Node + Send + Sync> doesn't implements Debug, so unwrap_err is not an option
Expand Down Expand Up @@ -581,11 +581,11 @@ mod tests {

// spawn 2 dummy nodes to populate namespace
namespace
.spawn_node(SpawnNodeOptions::new("mynode1", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode1", "/path/to/my/node_binary"))
.await
.unwrap();
namespace
.spawn_node(SpawnNodeOptions::new("mynode2", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode2", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down
32 changes: 16 additions & 16 deletions crates/provider/src/native/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -363,7 +363,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -431,7 +431,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -474,7 +474,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -509,7 +509,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -556,7 +556,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -611,7 +611,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -652,7 +652,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -711,7 +711,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -808,7 +808,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -844,7 +844,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -966,7 +966,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -1012,7 +1012,7 @@ mod tests {

let node = namespace
.spawn_node(
SpawnNodeOptions::new("mynode", "/path/to/my/node_binary")
&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary")
.args(vec![
"-flag1",
"--flag2",
Expand Down Expand Up @@ -1168,7 +1168,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -1203,7 +1203,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down Expand Up @@ -1280,7 +1280,7 @@ mod tests {

// spawn dummy node
let node = namespace
.spawn_node(SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.spawn_node(&SpawnNodeOptions::new("mynode", "/path/to/my/node_binary"))
.await
.unwrap();

Expand Down

0 comments on commit aa7f6de

Please sign in to comment.