Skip to content

Commit

Permalink
update: setup and run fns
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Nov 12, 2024
1 parent fa75b56 commit 55c4454
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
57 changes: 54 additions & 3 deletions e2e-tests/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,58 @@ pub enum OrchestratorMode {
}

impl Orchestrator {
pub fn run(envs: Vec<(String, String)>, mode: OrchestratorMode) -> Self {
pub fn setup(envs: Vec<(String, String)>) {
let port = get_free_port();
let repository_root = &get_repository_root();
let port_str = format!("{}", port);

std::env::set_current_dir(repository_root).expect("Failed to change working directory");
let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat();

println!("Running orchestrator in Setup mode");
let mut command = Command::new("cargo");
command
.arg("run")
.arg("--release")
.arg("--bin")
.arg("orchestrator")
.arg("--features")
.arg("testing")
.arg("--")
// if mode::Run then --run else if mode::Setup then --setup
.arg("--setup")
.arg("--settle-on-ethereum")
.arg("--aws-s3")
.arg("--aws-sqs")
.arg("--aws-sns")
.arg("--mongodb")
.arg("--sharp")
.arg("--da-on-ethereum")
.arg("--aws-event-bridge")
.current_dir(repository_root)
.envs(envs)
.stdout(Stdio::piped())
.stderr(Stdio::piped());

let mut process = command.spawn().expect("Failed to start process");

// Wait for the process to complete and get its exit status
let status = process.wait().expect("Failed to wait for process");

// You can check if the process succeeded
if status.success() {
println!("Setup Orchestrator completed successfully");
} else {
// Get the exit code if available
if let Some(code) = status.code() {
println!("Setup Orchestrator failed with exit code: {}", code);
} else {
println!("Setup Orchestrator terminated by signal");
}
}
}

pub fn run(envs: Vec<(String, String)>) -> Self {
let port = get_free_port();
let address = format!("127.0.0.1:{}", port);
let repository_root = &get_repository_root();
Expand All @@ -46,7 +97,7 @@ impl Orchestrator {
let port_str = format!("{}", port);
let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat();

println!("Running orchestrator in {:?} mode", mode);
println!("Running orchestrator in Run mode");
let mut command = Command::new("cargo");
command
.arg("run")
Expand All @@ -57,7 +108,7 @@ impl Orchestrator {
.arg("testing")
.arg("--")
// if mode::Run then --run else if mode::Setup then --setup
.arg(format!("--{}", mode))
.arg("--run")
.arg("--settle-on-ethereum")
.arg("--aws-s3")
.arg("--aws-sqs")
Expand Down
6 changes: 2 additions & 4 deletions e2e-tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ impl Setup {
async fn test_orchestrator_workflow(#[case] l2_block_number: String) {
// Fetching the env vars from the test env file as these will be used in
// setting up of the test and during orchestrator run too.
use e2e_tests::node::OrchestratorMode;
dotenvy::from_filename(".env.test").expect("Failed to load the .env file");

let queue_params = AWSSQSValidatedArgs {
Expand All @@ -138,8 +137,7 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) {
let mut setup_config = Setup::new(l2_block_number.clone()).await;
// Setup Cloud
// Setup orchestrator cloud
let _orchestrator = Orchestrator::run(setup_config.envs(), OrchestratorMode::Setup);

Orchestrator::setup(setup_config.envs());
println!("✅ Orchestrator cloud setup completed");

// Step 1 : SNOS job runs =========================================
Expand All @@ -162,7 +160,7 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) {
println!("✅ Orchestrator setup completed.");

// Run orchestrator
let mut orchestrator = Orchestrator::run(setup_config.envs(), OrchestratorMode::Run);
let mut orchestrator = Orchestrator::run(setup_config.envs());
orchestrator.wait_till_started().await;

println!("✅ Orchestrator started");
Expand Down

0 comments on commit 55c4454

Please sign in to comment.