test: add resumable isolated test harness
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user