MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestLockWriteBlocksRead

Function TestLockWriteBlocksRead

pkg/internal/filesystem/lock_test.go:228–273  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

226}
227
228func TestLockWriteBlocksRead(t *testing.T) {
229 t.Parallel()
230
231 var waitGroup sync.WaitGroup
232
233 var concurrentKey uint32
234
235 tempDir := t.TempDir()
236
237 waitGroup.Add(2)
238
239 // Start a lock, set the key, sleep 1s and confirm the key is still the same
240 go func() {
241 defer waitGroup.Done()
242
243 lErr := filesystem.WithLock(tempDir, func() error {
244 time.Sleep(1 * time.Second)
245
246 atomic.StoreUint32(&concurrentKey, routine1)
247
248 assert.Equal(t, atomic.LoadUint32(&concurrentKey), routine1)
249
250 return nil
251 })
252
253 assert.NilError(t, lErr, "locking should not error")
254 }()
255
256 time.Sleep(50 * time.Millisecond)
257
258 // Start a readonly lock immediately
259 // Confirm the key has been set by the write lock
260 go func() {
261 defer waitGroup.Done()
262
263 lErr := filesystem.WithReadOnlyLock(tempDir, func() error {
264 assert.Equal(t, atomic.LoadUint32(&concurrentKey), routine1)
265
266 return nil
267 })
268
269 assert.NilError(t, lErr, "locking should not error")
270 }()
271
272 waitGroup.Wait()
273}

Callers

nothing calls this directly

Calls 5

WithLockFunction · 0.92
WithReadOnlyLockFunction · 0.92
AddMethod · 0.80
TempDirMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…