From cec5fb51077c8dad502d003084989c7e0d091a25 Mon Sep 17 00:00:00 2001 From: Huan-Cheng Chang Date: Fri, 15 Nov 2024 09:27:46 +0000 Subject: [PATCH] fix(jstzd): revise baker check in jstzd test --- crates/jstzd/tests/jstzd_test.rs | 33 +++++++++++++++++++++++++++----- nix/crates.nix | 4 ++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/crates/jstzd/tests/jstzd_test.rs b/crates/jstzd/tests/jstzd_test.rs index 3b42cae7d..ef85afffd 100644 --- a/crates/jstzd/tests/jstzd_test.rs +++ b/crates/jstzd/tests/jstzd_test.rs @@ -1,5 +1,6 @@ mod utils; use std::path::PathBuf; +use tempfile::{NamedTempFile, TempPath}; use jstzd::task::utils::retry; use jstzd::{EXCHANGER_ADDRESS, JSTZ_NATIVE_BRIDGE_ADDRESS}; @@ -8,7 +9,7 @@ use octez::r#async::client::{OctezClient, OctezClientConfigBuilder}; use octez::r#async::endpoint::Endpoint; use octez::r#async::node_config::{OctezNodeConfigBuilder, OctezNodeRunOptionsBuilder}; use octez::r#async::protocol::{ - BootstrapAccount, BootstrapContract, ProtocolParameterBuilder, + BootstrapAccount, BootstrapContract, Protocol, ProtocolParameterBuilder, }; use octez::unused_port; use utils::get_block_level; @@ -49,8 +50,12 @@ async fn jstzd_test() { OctezClientConfigBuilder::new(octez_node_config.rpc_endpoint.clone()) .build() .unwrap(); + + let baker_path = + create_baker_executable_copy(protocol_params.protocol().clone()).await; + let baker_executable_name = baker_path.file_name().unwrap().to_str().unwrap(); let baker_config = OctezBakerConfigBuilder::new() - .set_binary_path(BakerBinaryPath::Env(protocol_params.protocol().clone())) + .set_binary_path(BakerBinaryPath::Custom(baker_path.to_path_buf())) .set_octez_client_base_dir( PathBuf::from(octez_client_config.base_dir()) .to_str() @@ -87,7 +92,7 @@ async fn jstzd_test() { assert!(node_running); let baker_running = retry(30, 1000, || async { - if run_ps().await.contains("octez-baker") { + if run_ps().await.contains(baker_executable_name) { let last_level = get_block_level(&rpc_endpoint.to_string()).await; return Ok(last_level > 2); } @@ -128,7 +133,7 @@ async fn jstzd_test() { assert!(node_destroyed); let baker_destroyed = retry(30, 1000, || async { - Ok(!run_ps().await.contains("octez-baker")) + Ok(!run_ps().await.contains(baker_executable_name)) }) .await; assert!(baker_destroyed); @@ -142,7 +147,7 @@ async fn jstzd_test() { async fn run_ps() -> String { let output = tokio::process::Command::new("ps") // print with extra columns so that commands don't get truncated too much - .args(["-o", "comm"]) + .args(["-o", "args"]) .env("COLUMNS", "1000") .output() .await @@ -151,6 +156,24 @@ async fn run_ps() -> String { String::from_utf8(output.stdout).unwrap() } +async fn create_baker_executable_copy(protocol: Protocol) -> TempPath { + let baker_path = PathBuf::from( + String::from_utf8( + tokio::process::Command::new("which") + .arg(BakerBinaryPath::Env(protocol).to_string()) + .output() + .await + .unwrap() + .stdout, + ) + .unwrap() + .trim(), + ); + let tmp_path = NamedTempFile::new().unwrap().into_temp_path(); + tokio::fs::copy(baker_path, &tmp_path).await.unwrap(); + tmp_path +} + async fn read_bootstrap_contracts() -> Vec { let mut contracts = vec![]; for (contract_name, hash) in CONTRACT_NAMES { diff --git a/nix/crates.nix b/nix/crates.nix index d966481eb..d7a73f4ed 100644 --- a/nix/crates.nix +++ b/nix/crates.nix @@ -127,7 +127,7 @@ in { cargo-test-int = craneLib.cargoNextest (commonWorkspace // { - buildInputs = commonWorkspace.buildInputs ++ [pkgs.iana-etc octez pkgs.cacert pkgs.ps]; + buildInputs = commonWorkspace.buildInputs ++ [pkgs.iana-etc octez pkgs.cacert pkgs.which pkgs.ps]; doCheck = true; # Run the integration tests # @@ -140,7 +140,7 @@ in { cargo-llvm-cov = craneLib.cargoLlvmCov (commonWorkspace // { - buildInputs = commonWorkspace.buildInputs ++ [pkgs.iana-etc octez pkgs.cacert pkgs.ps]; + buildInputs = commonWorkspace.buildInputs ++ [pkgs.iana-etc octez pkgs.cacert pkgs.which pkgs.ps]; # Generate coverage reports for codecov cargoLlvmCovExtraArgs = "--workspace --exclude-from-test \"jstz_api\" --codecov --output-path $out"; });