(t *testing.T)
| 814 | } |
| 815 | |
| 816 | func TestFileLockRefCountUsesPathLock(t *testing.T) { |
| 817 | path := "/tmp/" + t.Name() |
| 818 | otherPath := path + "-other" |
| 819 | t.Cleanup(func() { |
| 820 | filesLockMu.Lock() |
| 821 | delete(filesLockMap, path) |
| 822 | delete(filesLockMap, otherPath) |
| 823 | filesLockMu.Unlock() |
| 824 | }) |
| 825 | |
| 826 | firstLock := acquireFileLock(path) |
| 827 | secondLock := acquireFileLock(path) |
| 828 | if firstLock != secondLock { |
| 829 | t.Fatalf("same path must return same lock") |
| 830 | } |
| 831 | |
| 832 | otherLock := acquireFileLock(otherPath) |
| 833 | if firstLock == otherLock { |
| 834 | t.Fatalf("different paths must not share locks") |
| 835 | } |
| 836 | |
| 837 | releaseFileLock(path, firstLock) |
| 838 | filesLockMu.Lock() |
| 839 | remainingRefs := 0 |
| 840 | if lock := filesLockMap[path]; lock != nil { |
| 841 | remainingRefs = lock.refs |
| 842 | } |
| 843 | filesLockMu.Unlock() |
| 844 | if remainingRefs != 1 { |
| 845 | t.Fatalf("unexpected remaining refs %d. Expecting 1", remainingRefs) |
| 846 | } |
| 847 | |
| 848 | releaseFileLock(path, secondLock) |
| 849 | filesLockMu.Lock() |
| 850 | _, ok := filesLockMap[path] |
| 851 | filesLockMu.Unlock() |
| 852 | if ok { |
| 853 | t.Fatalf("lock was not removed") |
| 854 | } |
| 855 | |
| 856 | releaseFileLock(otherPath, otherLock) |
| 857 | filesLockMu.Lock() |
| 858 | _, ok = filesLockMap[otherPath] |
| 859 | filesLockMu.Unlock() |
| 860 | if ok { |
| 861 | t.Fatalf("other lock was not removed") |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | func TestFileLockWaiterKeepsEntry(t *testing.T) { |
| 866 | path := "/tmp/" + t.Name() |
nothing calls this directly
no test coverage detected
searching dependent graphs…