MCPcopy
hub / github.com/valyala/fasthttp / TestFileLockRefCountUsesPathLock

Function TestFileLockRefCountUsesPathLock

fs_test.go:816–863  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

814}
815
816func 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
865func TestFileLockWaiterKeepsEntry(t *testing.T) {
866 path := "/tmp/" + t.Name()

Callers

nothing calls this directly

Calls 4

acquireFileLockFunction · 0.85
releaseFileLockFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…