From 3a829518489b1507305fb34ec2e6adf0c7d145f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 6 Dec 2024 17:52:24 +0100 Subject: [PATCH] test: fix "it_removes_lassie_temp_on_start" (#631) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add more diagnostics to simplify troubleshooting in the future. Here is how to run this single test and get the additional info: ``` cargo test --test daemon_tests -- --nocapture ``` Signed-off-by: Miroslav Bajtoš --- daemon/tests/daemon_tests.rs | 20 ++++++++++++------- .../tests/fixtures/fetch-ipfs-with-delay.js | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/daemon/tests/daemon_tests.rs b/daemon/tests/daemon_tests.rs index 41e3eeca..bbf6b10e 100644 --- a/daemon/tests/daemon_tests.rs +++ b/daemon/tests/daemon_tests.rs @@ -36,6 +36,8 @@ pub fn it_removes_lassie_temp_on_start() { cmd.stderr(Stdio::null()); } + println!("Starting zinniad in background"); + // Start zinniad in background let mut child = cmd .spawn() @@ -45,16 +47,20 @@ pub fn it_removes_lassie_temp_on_start() { .map(|it| it.expect("cannot read from child's stdout")) .inspect(|ln| println!("[zinniad] {}", ln)); - // Wait until our module starts and calls `fetch('ipfs://...')` + println!("Waiting for our module to start and call `fetch('ipfs://...')`"); stdout_lines .by_ref() .take_while(|ln| !ln.contains("fetch:start")) .for_each(drop); - // Wait until Lassie creates its temp file + let lassie_cache_dir = cache_root.join("lassie"); + println!( + "Waiting until Lassie creates its temp file in {}", + lassie_cache_dir.display() + ); loop { std::thread::sleep(Duration::from_millis(100)); - let file_count = read_dir(cache_root.join("lassie")) + let file_count = read_dir(&lassie_cache_dir) .expect("cannot list files in Lassie's temp dir") .count(); @@ -63,7 +69,7 @@ pub fn it_removes_lassie_temp_on_start() { } } - // Stop the process + println!("Killing the zinniad process"); // Note: on Unix, this sends SIGKILL signal which allows the process to shutdown gracefully // If we ever implement graceful shutdown for Lassie, then we may need to rework this line. child.kill().expect("cannot stop zinniad"); @@ -84,7 +90,7 @@ pub fn it_removes_lassie_temp_on_start() { "Lassie should have left some temp files" ); - // Run zinniad again + println!("Running zinniad again"); let mut child = cmd .spawn() .unwrap_or_else(|_| panic!("cannot spawn {:?}", cmd.get_program())); @@ -93,13 +99,13 @@ pub fn it_removes_lassie_temp_on_start() { .map(|it| it.expect("cannot read from child's stdout")) .inspect(|ln| println!("[zinniad] {}", ln)); - // Wait until our module starts and calls `fetch('ipfs://...')` + println!("Waiting for our module to start and call `fetch('ipfs://...')`"); stdout_lines .by_ref() .take_while(|ln| !ln.contains("fetch:start")) .for_each(drop); - // Stop the process + println!("Killing the zinniad process"); // Note: on Unix, this sends SIGKILL signal which allows the process to shutdown gracefully // If we ever implement graceful shutdown for Lassie, then we may need to rework this line. child.kill().expect("cannot stop zinniad"); diff --git a/daemon/tests/fixtures/fetch-ipfs-with-delay.js b/daemon/tests/fixtures/fetch-ipfs-with-delay.js index 3459fc2a..5df19b13 100644 --- a/daemon/tests/fixtures/fetch-ipfs-with-delay.js +++ b/daemon/tests/fixtures/fetch-ipfs-with-delay.js @@ -1,6 +1,6 @@ // Signal that we are going to start the retrieval Zinnia.activity.info("fetch:start"); -const response = await fetch("ipfs://QmdmQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm"); +const response = await fetch("ipfs://bafybeiazvkej6ou3w6xmva5ed6suonxjv3jkhq4ke73q5hgmcjmf76uos4"); Zinnia.activity.info("fetch:response-headers");