m/installer/test: prevent QEMU file lock race
Albeit rare on development machines, this flake showed up frequently in
CI. QEMU processes weren't being waited on to finish before the next VM
launch, leading to multiple processes attempting to lock the same file.
In addition, a go-diskfs image handle wasn't being closed, though only
in a read-only context.
Change-Id: I23529017f5473f9db24ad8e84ca2fa8a6a40d7e5
Reviewed-on: https://review.monogon.dev/c/monogon/+/699
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/installer/test/main.go b/metropolis/installer/test/main.go
index c4faf81..9f38b4d 100644
--- a/metropolis/installer/test/main.go
+++ b/metropolis/installer/test/main.go
@@ -113,6 +113,8 @@
return false, ctx.Err()
case line := <-lineC:
if strings.Contains(line, expectedOutput) {
+ qemuCmd.Process.Kill()
+ qemuCmd.Wait()
return true, nil
}
}
@@ -312,6 +314,7 @@
if err := checkEspContents(storage); err != nil {
t.Error(err.Error())
}
+ storage.File.Close()
// Run QEMU again. Expect TestOS to launch successfully.
expectedOutput = "_TESTOS_LAUNCH_SUCCESS_"
result, err = runQemu(ctx, qemuDriveParam(storagePath), expectedOutput)