Update volume_growth_reservation_test.go
This commit is contained in:
@@ -139,6 +139,7 @@ func TestVolumeGrowth_ConcurrentAllocationPreventsRaceCondition(t *testing.T) {
|
|||||||
const concurrentRequests = 10
|
const concurrentRequests = 10
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var successCount, failureCount atomic.Int32
|
var successCount, failureCount atomic.Int32
|
||||||
|
var commitMutex sync.Mutex // Ensures atomic commit of volume creation + reservation release
|
||||||
|
|
||||||
for i := 0; i < concurrentRequests; i++ {
|
for i := 0; i < concurrentRequests; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@@ -156,6 +157,8 @@ func TestVolumeGrowth_ConcurrentAllocationPreventsRaceCondition(t *testing.T) {
|
|||||||
|
|
||||||
// Simulate completion: increment volume count BEFORE releasing reservation
|
// Simulate completion: increment volume count BEFORE releasing reservation
|
||||||
if reservation != nil {
|
if reservation != nil {
|
||||||
|
commitMutex.Lock()
|
||||||
|
|
||||||
// First, increment the volume count to reflect the created volume
|
// First, increment the volume count to reflect the created volume
|
||||||
// Acquire lock briefly to access children map, then release before updating
|
// Acquire lock briefly to access children map, then release before updating
|
||||||
dn.RLock()
|
dn.RLock()
|
||||||
@@ -169,6 +172,8 @@ func TestVolumeGrowth_ConcurrentAllocationPreventsRaceCondition(t *testing.T) {
|
|||||||
|
|
||||||
// Then release the reservation
|
// Then release the reservation
|
||||||
reservation.releaseAllReservations()
|
reservation.releaseAllReservations()
|
||||||
|
|
||||||
|
commitMutex.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(i)
|
}(i)
|
||||||
|
|||||||
Reference in New Issue
Block a user