MCPcopy
hub / github.com/go-redsync/redsync / TestMutexLockUnlockSplit

Function TestMutexLockUnlockSplit

mutex_test.go:304–328  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

302}
303
304func TestMutexLockUnlockSplit(t *testing.T) {
305 ctx := context.Background()
306 for k, v := range makeCases(4) {
307 t.Run(k, func(t *testing.T) {
308 rs := New(v.pools...)
309 key := "test-split-lock"
310
311 mutex1 := rs.NewMutex(key, WithExpiry(time.Hour))
312 err := mutex1.Lock()
313 if err != nil {
314 t.Fatalf("mutex lock failed: %s", err)
315 }
316 assertAcquired(ctx, t, v.pools, mutex1)
317
318 mutex2 := rs.NewMutex(key, WithExpiry(time.Hour), WithValue(mutex1.Value()))
319 ok, err := mutex2.Unlock()
320 if err != nil {
321 t.Fatalf("mutex unlock failed: %s", err)
322 }
323 if !ok {
324 t.Fatalf("Expected a valid mutex")
325 }
326 })
327 }
328}
329
330func getPoolValues(ctx context.Context, pools []redis.Pool, name string) []string {
331 values := make([]string, len(pools))

Callers

nothing calls this directly

Calls 9

LockMethod · 0.95
ValueMethod · 0.95
UnlockMethod · 0.95
makeCasesFunction · 0.85
NewFunction · 0.85
WithExpiryFunction · 0.85
assertAcquiredFunction · 0.85
WithValueFunction · 0.85
NewMutexMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…