MCPcopy Create free account
hub / github.com/cli/cli / TestLockBlocksUntilUnlocked

Function TestLockBlocksUntilUnlocked

internal/flock/flock_test.go:112–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

110}
111
112func TestLockBlocksUntilUnlocked(t *testing.T) {
113 lockPath := filepath.Join(t.TempDir(), "contended.lock")
114
115 _, unlock, err := flock.TryLock(lockPath)
116 require.NoError(t, err)
117
118 acquired := make(chan struct{})
119 go func() {
120 _, unlock2, err := flock.Lock(t.Context(), lockPath)
121 assert.NoError(t, err)
122 close(acquired)
123 unlock2()
124 }()
125
126 select {
127 case <-acquired:
128 t.Fatal("Lock returned while the lock was still held")
129 case <-time.After(100 * time.Millisecond):
130 }
131
132 unlock()
133
134 select {
135 case <-acquired:
136 case <-time.After(2 * time.Second):
137 t.Fatal("Lock did not acquire after the holder released it")
138 }
139}
140
141func TestLockReturnsNonContentionError(t *testing.T) {
142 lockPath := filepath.Join(t.TempDir(), "no", "such", "dir", "test.lock")

Callers

nothing calls this directly

Calls 3

TryLockFunction · 0.92
LockFunction · 0.92
JoinMethod · 0.80

Tested by

no test coverage detected