Skip to content

Latest commit

 

History

History
86 lines (64 loc) · 3.01 KB

File metadata and controls

86 lines (64 loc) · 3.01 KB

Max Limits Verification Summary

✅ Client-Side Defaults

Read Locks (rw-client.ts and rw-write-preferred-client.ts)

  • Default: max = 10 (if not explicitly set)
  • Explicit values honored: If user sets max=1, max=5, etc., it's respected
  • Code location:
    • src/rw-client.ts:185-186
    • src/rw-write-preferred-client.ts:281-282

Write Locks (rw-client.ts)

  • Default: max = 1 (always exclusive)
  • Code location: src/rw-client.ts:138

✅ Broker-Side Logic

New Lock Creation (broker.ts and broker-1.ts)

  • When lock doesn't exist, getDefaultLockObject(key, keepLocksAfterDeath, max) is called
  • Uses max || 1 as fallback
  • If client sends max=10, lock is created with max=10
  • Code location: src/broker.ts:1532, src/broker.ts:979-983

Existing Lock Max Update (broker.ts and broker-1.ts)

  • Updates lck.max if Number.isInteger(max) is true (line 1374-1376)
  • Uses new max if provided, otherwise uses existing lck.max (line 1388)
  • Handles both increasing and decreasing max correctly

Limit Enforcement

  • For read locks: Checks lck.readers + 1 against effectiveMax
  • For write locks: Checks lockholders.size against effectiveMax
  • Queues requests when effectiveCount >= effectiveMax (line 1393)

Warning Logic (Prevents False Positives)

  • Only warns when effectiveCount > effectiveMax (not >=)
  • Doesn't warn for write locks queuing behind readers (expected)
  • Doesn't warn if max was just increased to accommodate current count
  • Code location: src/broker.ts:1410-1412

✅ Test Coverage

Test File: test/rw-max-limits-test.ts

  1. Test 1: Write Lock Max=1

    • Verifies only 1 writer at a time
    • Tests exclusive write access
  2. Test 2: Read Lock Max=10 (Default)

    • Verifies 10 concurrent readers allowed
    • No false positive warnings
  3. Test 3: Read Lock Max=1 (Honored)

    • Verifies explicit max=1 is respected
    • Only 1 reader allowed when max=1
  4. Test 4: Read Lock Max=5 (Honored)

    • Verifies explicit max=5 is respected
    • Up to 5 readers allowed
  5. Test 5: Read Lock Max=10 Exceeded

    • Tests handling when limit is exceeded
    • Verifies limit enforcement

✅ Edge Cases Verified

  1. First lock request: Max value from client is used correctly
  2. Subsequent requests with same max: No issues
  3. Max increased: Handled correctly (e.g., from 1 to 10)
  4. Max decreased: Handled correctly (e.g., from 10 to 1)
  5. Concurrent requests: Race conditions handled properly
  6. False positives: No warnings when within limits
  7. False negatives: Warnings appear when limits exceeded

✅ Code Consistency

  • broker.ts and broker-1.ts have identical logic
  • rw-client.ts and rw-write-preferred-client.ts have consistent defaults
  • All code paths tested and verified

Conclusion

All max limits are properly honoredNo false positives or false negativesComprehensive test coverageEdge cases handled correctly