Skip to content

Commit d6f93fa

Browse files
fix(tmachine): keep the SSH port check and name a run with no tests
Restore the check that the SSH forward port is free before QEMU starts. QEMU reports a taken port only by exiting, so a layer build would otherwise run its playbooks against the VM that already holds the port and cache the result. Report nextest's no-tests exit code as "no test ran" instead of a bare exit status. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 193adc4 commit d6f93fa

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎tests/runner/src/execute.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const READY_SLACK: Duration = Duration::from_mins(1);
3434
/// nextest's exit code when a test failed, as opposed to nextest itself
3535
/// failing.
3636
const NEXTEST_TEST_FAILED: i32 = 100;
37+
/// nextest's exit code when `--no-tests fail` found no tests to run.
38+
const NEXTEST_NO_TESTS_RUN: i32 = 4;
3739
/// How much of the end of the nextest log to print after a failure. nextest
3840
/// ends its output with a summary that names the failed tests.
3941
const LOG_TAIL_LINES: usize = 40;
@@ -59,6 +61,9 @@ impl Status {
5961
match status.code() {
6062
Some(0) => Self::Passed,
6163
Some(NEXTEST_TEST_FAILED) => Self::Failed,
64+
Some(NEXTEST_NO_TESTS_RUN) => {
65+
Self::Error(format!("no test ran; see {}", log.display()))
66+
}
6267
_ => Self::Error(format!(
6368
"nextest exited with {status}; see {}",
6469
log.display()
@@ -335,7 +340,10 @@ mod tests {
335340
let status = |code| Status::of_nextest(ExitStatus::from_raw(code << 8), Path::new("log"));
336341
assert_eq!(status(0), Status::Passed);
337342
assert_eq!(status(NEXTEST_TEST_FAILED), Status::Failed);
338-
// No tests ran, or nextest itself failed.
339-
assert!(matches!(status(4), Status::Error(_)));
343+
assert_eq!(
344+
status(NEXTEST_NO_TESTS_RUN),
345+
Status::Error("no test ran; see log".to_string())
346+
);
347+
assert!(matches!(status(1), Status::Error(_)));
340348
}
341349
}

‎tests/tmachine/src/qemu/vm.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#[cfg(target_arch = "aarch64")]
55
use std::fs;
6+
use std::net::{Ipv4Addr, TcpListener};
67
#[cfg(target_arch = "aarch64")]
78
use std::os::unix::fs::PermissionsExt;
89
use std::path::Path;
@@ -69,6 +70,16 @@ pub(super) struct QemuVm {
6970

7071
impl QemuVm {
7172
pub(super) async fn start(image: &QemuImage) -> Result<Self> {
73+
let port = ssh_port();
74+
// QEMU reports a taken port only by exiting, and Ansible would then
75+
// provision whatever VM already holds the port. The check can race
76+
// another process, but it catches a second tmachine run.
77+
TcpListener::bind((Ipv4Addr::LOCALHOST, port)).with_context(|| {
78+
format!(
79+
"host port {port} is not available for the VM's SSH forward; is another tmachine VM running? Set TMACHINE_SSH_PORT to use another port"
80+
)
81+
})?;
82+
7283
let runtime_dir = tempdir().context("create VM runtime directory")?;
7384
let qmp_socket = runtime_dir.path().join("qmp.sock");
7485
ensure!(
@@ -77,7 +88,7 @@ impl QemuVm {
7788
qmp_socket.display()
7889
);
7990
let firmware = prepare_firmware(runtime_dir.path())?;
80-
let child = command(image, &qmp_socket, firmware.as_ref(), ssh_port())
91+
let child = command(image, &qmp_socket, firmware.as_ref(), port)
8192
.spawn()
8293
.context("start QEMU")?;
8394

0 commit comments

Comments
 (0)