Skip to content

Commit

Permalink
test: fix "it_removes_lassie_temp_on_start" (#631)
Browse files Browse the repository at this point in the history
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š <[email protected]>
  • Loading branch information
bajtos authored Dec 6, 2024
1 parent 43f22de commit 3a82951
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions daemon/tests/daemon_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();

Expand All @@ -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");
Expand All @@ -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()));
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion daemon/tests/fixtures/fetch-ipfs-with-delay.js
Original file line number Diff line number Diff line change
@@ -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");

Expand Down

0 comments on commit 3a82951

Please sign in to comment.