test: add resumable isolated test harness

This commit is contained in:
2026-08-31 08:32:23 +00:00
parent 31a1314470
commit d6d93f3d98
11 changed files with 837 additions and 19 deletions
+24
View File
@@ -0,0 +1,24 @@
//go:build !windows
package main
import (
"fmt"
"os"
"syscall"
)
func acquireLock(path string) (func(), error) {
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o600)
if err != nil {
return nil, err
}
if err := syscall.Flock(int(file.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
_ = file.Close()
return nil, fmt.Errorf("another test harness process holds %s: %w", path, err)
}
return func() {
_ = syscall.Flock(int(file.Fd()), syscall.LOCK_UN)
_ = file.Close()
}, nil
}