Task 3-2: Integration Test - Concurrent Confirm (Race Condition)
Phase: 3 - Testing Priority: High Depends on: task-1-2 Reference: docs/BountyHunter-Backend/details/feature-nft-management/SPEC.md
Background
Test race condition khi 2 renters cùng lúc gọi confirm-rent cho cùng 1 rental order. Sau khi task-1-2 thêm distributed lock, cần verify lock hoạt động đúng.
Test scenarios
Concurrent confirm - 2 renters
- [ ] Setup: 1 rental order
status=NEW_VERIFIED - [ ] 2 renters gọi
PUT /confirm-rent/{orderId}đồng thời (thread A và thread B) — dùngCountDownLatchhoặc parallel HTTP requests - [ ] Expected: chỉ 1 renter thành công (
status=RENTING), 1 nhận errorRENTAL_ORDER_NOT_AVAILABLE - [ ] Verify: chỉ 1 renter bị charge B-Coin (balance check sau cả 2 requests hoàn tất)
- [ ] Verify: owner chỉ nhận 1 lần deposit
- [ ] Verify: order
status=RENTINGvới đúng 1renterId(không bị overwrite)
Lock timeout scenario
- [ ] Simulate lock holder chạy chậm (mock delay trong lock bằng
Thread.sleeptrong test) - [ ] Verify: other renter chờ hoặc nhận timeout error (không bị deadlock vô hạn)
- [ ] Verify: sau timeout → lock được release, order state consistent
After lock release
- [ ] Successful confirm → lock released
- [ ] Verify: order không thể confirm lần 2 (status guard
status != NEWblocks, không phải lock blocks) - [ ] Verify:
RENTAL_ORDER_NOT_AVAILABLEerror khi cố confirm order đãRENTING
Verification / Acceptance Criteria
- [ ] Concurrent confirm: đúng 1 success, đúng 1
RENTAL_ORDER_NOT_AVAILABLE - [ ] No double charge: tổng B-Coin bị deduct = 1 ×
rentalFee - [ ] No double credit: owner nhận đúng 1 lần
- [ ] Order
renterIdlà consistent (không bị race condition overwrite) - [ ] Lock timeout không gây deadlock — service vẫn responsive sau timeout
Files to Modify
- Test files trong
webmarketplace/src/test/hoặc integration test module