- 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-186src/rw-write-preferred-client.ts:281-282
- Default:
max = 1(always exclusive) - Code location:
src/rw-client.ts:138
- When lock doesn't exist,
getDefaultLockObject(key, keepLocksAfterDeath, max)is called - Uses
max || 1as fallback - If client sends
max=10, lock is created withmax=10 - Code location:
src/broker.ts:1532,src/broker.ts:979-983
- Updates
lck.maxifNumber.isInteger(max)is true (line 1374-1376) - Uses new
maxif provided, otherwise uses existinglck.max(line 1388) - Handles both increasing and decreasing max correctly
- For read locks: Checks
lck.readers + 1againsteffectiveMax - For write locks: Checks
lockholders.sizeagainsteffectiveMax - Queues requests when
effectiveCount >= effectiveMax(line 1393)
- 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 1: Write Lock Max=1 ✅
- Verifies only 1 writer at a time
- Tests exclusive write access
-
Test 2: Read Lock Max=10 (Default) ✅
- Verifies 10 concurrent readers allowed
- No false positive warnings
-
Test 3: Read Lock Max=1 (Honored) ✅
- Verifies explicit
max=1is respected - Only 1 reader allowed when max=1
- Verifies explicit
-
Test 4: Read Lock Max=5 (Honored) ✅
- Verifies explicit
max=5is respected - Up to 5 readers allowed
- Verifies explicit
-
Test 5: Read Lock Max=10 Exceeded ✅
- Tests handling when limit is exceeded
- Verifies limit enforcement
- First lock request: Max value from client is used correctly
- Subsequent requests with same max: No issues
- Max increased: Handled correctly (e.g., from 1 to 10)
- Max decreased: Handled correctly (e.g., from 10 to 1)
- Concurrent requests: Race conditions handled properly
- False positives: No warnings when within limits
- False negatives: Warnings appear when limits exceeded
broker.tsandbroker-1.tshave identical logicrw-client.tsandrw-write-preferred-client.tshave consistent defaults- All code paths tested and verified
✅ All max limits are properly honored ✅ No false positives or false negatives ✅ Comprehensive test coverage ✅ Edge cases handled correctly