Skip to content

Commit 3eca486

Browse files
Olivier Bonnaureclaude
andcommitted
test: a failing test shows its servers' logs, which were always empty
The harness sent the server's stdout to /dev/null and kept stderr in stderr-<port>.log, but the server logs through tracing's default writer, stdout: every log file was empty, including the one cluster_7b's own diagnostic prints. Both streams now go to that file, and a Server dropped while its test is panicking prints the last 60 lines, since a CI runner's temp directory is gone afterwards. The manual-failover test also prints both nodes' INFO replication and CLUSTER NODES when it gives up: it fails on GitHub's runners now and then and could not be reproduced on two pinned cores, one, or one shared with a busy loop (0 in 25). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ee3e464 commit 3eca486

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

‎crates/solikv-server/tests/cluster_6.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,15 @@ fn a_manual_failover_swaps_master_and_replica() {
342342
}
343343
false
344344
});
345-
assert!(done, "manual failover did not complete in three attempts");
345+
assert!(
346+
done,
347+
"manual failover did not complete in three attempts\n\
348+
replica:\n{}{}\nmaster:\n{}{}",
349+
replica.c().info("replication"),
350+
replica.c().bulk(&["CLUSTER", "NODES"]),
351+
nodes[1].c().info("replication"),
352+
nodes[1].c().bulk(&["CLUSTER", "NODES"]),
353+
);
346354
wait_until(Duration::from_secs(20), || cluster_ok_any(&replica));
347355
let mut cr = replica.c();
348356
assert_eq!(cr.get(&key).as_deref(), Some("before"));

‎crates/solikv-server/tests/common/mod.rs‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ impl Drop for TmpDir {
5858
pub struct Server {
5959
pub child: Child,
6060
pub port: u16,
61+
/// The server's stderr, shown when a test fails (its directory goes
62+
/// with the test).
63+
pub log: Option<PathBuf>,
6164
}
6265

6366
impl Server {
@@ -66,14 +69,17 @@ impl Server {
6669
}
6770

6871
pub fn start_on(port: u16, dir: &Path, extra: &[&str]) -> Self {
69-
let log = std::fs::File::create(dir.join(format!("stderr-{port}.log"))).unwrap();
72+
// The server logs to stdout (tracing's default writer): both
73+
// streams go to one file, or the log would always be empty.
74+
let log_path = dir.join(format!("stderr-{port}.log"));
75+
let log = std::fs::File::create(&log_path).unwrap();
7076
let child = Command::new(env!("CARGO_BIN_EXE_solikv"))
7177
.args(["--port", &port.to_string(), "--rest-port", "0"])
7278
.args(["--bind", "127.0.0.1", "--log-level", "info"])
7379
.arg("--dir")
7480
.arg(dir)
7581
.args(extra)
76-
.stdout(Stdio::null())
82+
.stdout(Stdio::from(log.try_clone().unwrap()))
7783
.stderr(Stdio::from(log))
7884
.spawn()
7985
.expect("spawn solikv");
@@ -82,7 +88,11 @@ impl Server {
8288
assert!(Instant::now() < deadline, "server did not start");
8389
std::thread::sleep(Duration::from_millis(20));
8490
}
85-
Self { child, port }
91+
Self {
92+
child,
93+
port,
94+
log: Some(log_path),
95+
}
8696
}
8797

8898
fn answers(port: u16) -> bool {
@@ -124,6 +134,21 @@ impl Drop for Server {
124134
fn drop(&mut self) {
125135
let _ = self.child.kill();
126136
let _ = self.child.wait();
137+
// A failing test: what the server logged is often the only account
138+
// of why (a CI runner's temp directory is gone afterwards).
139+
if std::thread::panicking() {
140+
if let Some(text) = self
141+
.log
142+
.as_ref()
143+
.and_then(|p| std::fs::read_to_string(p).ok())
144+
{
145+
let lines: Vec<&str> = text.lines().collect();
146+
eprintln!("--- server :{} log, last 60 lines ---", self.port);
147+
for l in &lines[lines.len().saturating_sub(60)..] {
148+
eprintln!("{l}");
149+
}
150+
}
151+
}
127152
}
128153
}
129154

‎crates/solikv-server/tests/tls_7b.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ fn start_tls(dir: &Path, port: u16, args: &[String], client: Arc<rustls::ClientC
195195
.stderr(Stdio::from(log))
196196
.spawn()
197197
.expect("spawn solikv");
198-
let srv = Server { child, port };
198+
let srv = Server {
199+
child,
200+
port,
201+
log: None,
202+
};
199203
let rt = tokio::runtime::Builder::new_current_thread()
200204
.enable_all()
201205
.build()

0 commit comments

Comments
 (0)