test: serialize Windows POSIX shell fixtures across packages

This commit is contained in:
Nwflower committed 2026-12-01 09:24:18 -07:00
1 parent 53627e5e1a
commit dbf475d55c
12 files changed
+148 -18

No files matched your search

@@ -0,0 +1,7 @@
//go:build !windows
package shelllock
func Acquire() (func(), error) {
return func() {}, nil
}
@@ -0,0 +1,43 @@
//go:build windows
package shelllock
import (
"errors"
"fmt"
"runtime"
"golang.org/x/sys/windows"
)
const mutexName = `Local\ReimsGo-Test-MSYS`
func Acquire() (func(), error) {
runtime.LockOSThread()
name, err := windows.UTF16PtrFromString(mutexName)
if err != nil {
runtime.UnlockOSThread()
return nil, err
}
handle, err := windows.CreateMutex(nil, false, name)
if err != nil && !errors.Is(err, windows.ERROR_ALREADY_EXISTS) {
runtime.UnlockOSThread()
return nil, fmt.Errorf("create MSYS test mutex: %w", err)
}
event, err := windows.WaitForSingleObject(handle, windows.INFINITE)
if err != nil {
_ = windows.CloseHandle(handle)
runtime.UnlockOSThread()
return nil, fmt.Errorf("wait for MSYS test mutex: %w", err)
}
if event != windows.WAIT_OBJECT_0 && event != windows.WAIT_ABANDONED {
_ = windows.CloseHandle(handle)
runtime.UnlockOSThread()
return nil, fmt.Errorf("unexpected MSYS test mutex result: %#x", event)
}
return func() {
_ = windows.ReleaseMutex(handle)
_ = windows.CloseHandle(handle)
runtime.UnlockOSThread()
}, nil
}