| 1 | package workspacelease |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func unrelatedTreePath(t *testing.T, blocker *Owner, base string) (string, string) { |
| 11 | t.Helper() |
| 12 | blockedSlot := blocker.treeLockPath(blocker.canonical) |
| 13 | for i := 1; i < treeLockStripes*2; i++ { |
| 14 | root := filepath.Join(base, fmt.Sprintf("workspace-%d", i)) |
| 15 | path := filepath.Join(root, "b.go") |
| 16 | rootKey, _, err := canonicalFileKey(root) |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | pathKey, _, err := canonicalFileKey(path) |
| 21 | if err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if blocker.treeLockPath(rootKey) == blockedSlot || blocker.treeLockPath(pathKey) == blockedSlot { |
| 25 | continue |
| 26 | } |
| 27 | if err := os.Mkdir(root, 0o700); err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | return root, path |
| 31 | } |
| 32 | t.Fatal("could not find unrelated hierarchy lock slots") |
| 33 | return "", "" |
| 34 | } |
| 35 | |
| 36 | func distinctPathSlotInDirectory(t *testing.T, owner *Owner, dir, blockedSlot string) string { |
| 37 | t.Helper() |
| 38 | for i := range pathLockStripes * 2 { |
| 39 | path := filepath.Join(dir, fmt.Sprintf("parallel-%d.go", i)) |
| 40 | if canonicalPathSlot(t, owner, path) != blockedSlot { |
| 41 | return path |
| 42 | } |
| 43 | } |
| 44 | t.Fatal("could not find a distinct path stripe in the requested directory") |
| 45 | return "" |
| 46 | } |
| 47 |