summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/common/mod.rs4
-rw-r--r--tests/live.rs33
2 files changed, 36 insertions, 1 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 4884a19..1399179 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -430,7 +430,9 @@ fn copy_tree(from: &Path, to: &Path) {
if entry.file_type().unwrap().is_dir() {
copy_tree(&path, &target);
} else {
- std::fs::copy(&path, &target).unwrap();
+ std::fs::copy(&path, &target).unwrap_or_else(|e| {
+ panic!("copying {} to {}: {e}", path.display(), target.display())
+ });
}
}
}
diff --git a/tests/live.rs b/tests/live.rs
index b73b2f6..b891b7e 100644
--- a/tests/live.rs
+++ b/tests/live.rs
@@ -68,6 +68,39 @@ fn the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends() {
assert!(body.contains("\n\n"), "not event-framed: {body}");
}
+fn read_event(tail: &mut aur_build::http::sse::LogTail) -> String {
+ let mut buf = [0u8; 4096];
+ let n = tail.read(&mut buf).expect("tail");
+ String::from_utf8_lossy(&buf[..n]).into_owned()
+}
+
+#[test]
+fn the_tail_hands_over_each_append_as_it_lands_and_then_ends() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let id = queued(&env, "plain-make");
+ let log = env.cfg.build_log_path(&id);
+ std::fs::create_dir_all(log.parent().unwrap()).unwrap();
+ std::fs::write(&log, "==> step materialize\n").unwrap();
+
+ // Driven directly rather than over the socket, because the response is
+ // buffered until it ends: over HTTP every line lands in one read whatever
+ // the tail is doing, so the socket cannot show delivery per append.
+ let mut tail = aur_build::http::sse::LogTail::new(&env.cfg, env.db.clone(), &id);
+ assert_eq!(read_event(&mut tail), "data: ==> step materialize\n\n");
+ append(&log, "==> step build\n");
+ assert_eq!(
+ read_event(&mut tail),
+ "data: ==> step build\n\n",
+ "the second append did not arrive as an event of its own"
+ );
+ append(&log, "==> step publish\n");
+ assert_eq!(read_event(&mut tail), "data: ==> step publish\n\n");
+
+ builds::set_state(&env.db, &id, BuildState::Running, None).unwrap();
+ builds::set_state(&env.db, &id, BuildState::Succeeded, None).unwrap();
+ assert!(read_event(&mut tail).contains("event: end"), "the tail never ended");
+}
+
#[test]
fn the_log_stream_is_404_for_a_build_that_does_not_exist() {
let (env, fx) = env_with_fixture("plain-make");