MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestMultiLocker_SingleKey

Function TestMultiLocker_SingleKey

internal/lock/lock_test.go:275–297  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

273}
274
275func TestMultiLocker_SingleKey(t *testing.T) {
276 db, mock := redismock.NewClientMock()
277
278 // Single key scenario
279 multiLocker := NewMultiLocker(db, []string{"single-key"}, "test-value")
280
281 assert.Equal(t, []string{"single-key"}, multiLocker.Keys())
282 assert.Len(t, multiLocker.lockers, 1)
283
284 // Lock
285 mock.ExpectSetNX("single-key", "test-value", 5*time.Second).SetVal(true)
286
287 err := multiLocker.Lock(context.Background(), 5*time.Second)
288 assert.NoError(t, err)
289
290 // Unlock
291 unlockScript := "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"
292 mock.ExpectEval(unlockScript, []string{"single-key"}, "test-value").SetVal(int64(1))
293
294 err = multiLocker.Unlock(context.Background())
295 assert.NoError(t, err)
296 assert.NoError(t, mock.ExpectationsWereMet())
297}

Callers

nothing calls this directly

Calls 4

KeysMethod · 0.95
LockMethod · 0.95
UnlockMethod · 0.95
NewMultiLockerFunction · 0.85

Tested by

no test coverage detected