review: loopd prints every startup notice before it binds; tests wait for "serving on"
The serve tests waited for the socket file, then killed `loopd` and read its stderr, but the socket is bound before its mode is set and before "serving on" and the broker notice are printed, so a kill in between lost those lines (`pointers` failed once under load in M5c-1 task 15). The broker notice now comes before the bind, so "serving on" is the last startup line, and the tests wait for it (`tests/support/serving.rs`). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
//! Tests for the `loopd serve` command. Do not edit.
|
||||
|
||||
#[path = "support/serving.rs"]
|
||||
mod serving;
|
||||
mod support;
|
||||
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::time::Duration;
|
||||
use support::{FakeServer, Home, Reply, tokenizer};
|
||||
|
||||
fn config_file(home: &Home, server: &FakeServer, expect_slots: u32) -> std::path::PathBuf {
|
||||
@@ -56,25 +57,16 @@ fn serve_runs_the_self_test_then_binds_the_socket_with_mode_0600() {
|
||||
healthy_routes(&server);
|
||||
let config = config_file(&home, &server, 2);
|
||||
let socket = home.dir.join("run").join("loop").join("loop.sock");
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_loopd"))
|
||||
let child = Command::new(env!("CARGO_BIN_EXE_loopd"))
|
||||
.args(["serve", "--config"])
|
||||
.arg(&config)
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let mut up = false;
|
||||
for _ in 0..200 {
|
||||
if socket.exists() {
|
||||
up = true;
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
// "serving on" comes after the mode is set; the socket stays after loopd is killed.
|
||||
let (up, stderr) = serving::stderr_once_serving(child);
|
||||
assert!(up, "loopd never said it was serving; stderr: {stderr}");
|
||||
let mode = std::fs::metadata(&socket).map(|m| m.permissions().mode() & 0o777);
|
||||
let _ = child.kill();
|
||||
let output = child.wait_with_output().unwrap();
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(up, "the socket never appeared; stderr: {stderr}");
|
||||
assert_eq!(mode.unwrap(), 0o600, "{stderr}");
|
||||
assert!(stderr.contains("selftest: ok"), "{stderr}");
|
||||
assert!(stderr.contains("serving on"), "{stderr}");
|
||||
|
||||
Reference in New Issue
Block a user