返回 DeepSeek-Reasonix
junction_windows_test.go
根目录 / internal / identitylock / junction_windows_test.go
1 //go:build windows
2
3 package identitylock
4
5 import (
6 "errors"
7 "os"
8 "os/exec"
9 "path/filepath"
10 "testing"
11
12 "reasonix/internal/filelock"
13 )
14
15 func TestJunctionLocksExcludeLegacyAndCurrentWriters(t *testing.T) {
16 root := t.TempDir()
17 target, alias := filepath.Join(root, "target"), filepath.Join(root, "alias")
18 if err := os.Mkdir(target, 0o700); err != nil {
19 t.Fatal(err)
20 }
21 if out, err := exec.Command("cmd", "/c", "mklink", "/J", alias, target).CombinedOutput(); err != nil {
22 t.Fatalf("create junction: %v: %s", err, out)
23 }
24 legacy, current := filepath.Join(alias, "config.lock"), filepath.Join(target, "config.lock")
25 for _, reverse := range []bool{false, true} {
26 first, second := filelock.TryAcquire, TryAcquire
27 if reverse {
28 first, second = TryAcquire, filelock.TryAcquire
29 }
30 release, err := first(legacy)
31 if err != nil {
32 t.Fatal(err)
33 }
34 other, err := second(current)
35 release()
36 if other != nil {
37 other()
38 }
39 if !errors.Is(err, ErrHeld) {
40 t.Fatalf("reverse=%v concurrent writer admitted: %v", reverse, err)
41 }
42 other, err = second(current)
43 if err != nil {
44 t.Fatalf("release stranded lock: %v", err)
45 }
46 other()
47 }
48 }
49
49 lines GO