Skip to content

Commit

Permalink
fix(jstzd): revise baker check in jstzd test
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Nov 19, 2024
1 parent b4799b3 commit cec5fb5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
33 changes: 28 additions & 5 deletions crates/jstzd/tests/jstzd_test.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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<BootstrapContract> {
let mut contracts = vec![];
for (contract_name, hash) in CONTRACT_NAMES {
Expand Down
4 changes: 2 additions & 2 deletions nix/crates.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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";
});
Expand Down

0 comments on commit cec5fb5

Please sign in to comment.