diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 23:38:28 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 23:38:28 +0000 |
| commit | 7e3369e92d154c8ed532b977d5dd541398b5197d (patch) | |
| tree | 004778bf0da815b10fc0095348b93bd005c736cc /tests/live.rs | |
| parent | 6a12e9a42aaf27236e9d2527d820b3ec47bb6947 (diff) | |
| download | aur-build-7e3369e92d154c8ed532b977d5dd541398b5197d.tar.gz aur-build-7e3369e92d154c8ed532b977d5dd541398b5197d.zip | |
tests: prove the per-append delivery directly on the tail
The HTTP test cannot show delivery per append: the stream response is buffered
until it ends, so every line lands in one read no matter what the tail is doing,
and the sleeps that used to stage the appends proved nothing. The property moves
to where it is observable - drive LogTail, append between reads, and each append
has to arrive as its own event. The socket test keeps proving the wiring, the
headers and the end event.
copy_tree now names the file it failed on, which it did not do before.
Diffstat (limited to 'tests/live.rs')
| -rw-r--r-- | tests/live.rs | 33 |
1 files changed, 33 insertions, 0 deletions
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"); |
