mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
enhance: fix unstable unit test (#46626)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> - Core invariant: TestWait must deterministically verify that FixedSizeAllocator.Wait() is notified when virtual resources are released, so an allocation blocked due to exhausted virtual capacity eventually succeeds after explicit deallocations. - Removed/simplified logic: replaced the previous flaky pattern that spawned 100 concurrent goroutines performing Reallocate with an explicit channel-synchronized release goroutine that performs 100 sequential negative Reallocate calls only after the test blocks on allocation. This eliminates timing-dependent concurrency and the nondeterministic i-based assertion. - Why no data loss or behavior regression: only the test changed — allocator implementation (Allocate/Reallocate/Release/Wait/notify) and public APIs are unchanged. The test now exercises the same code paths (Allocate fails, Wait blocks on cond, Reallocate/Release call notify), but in a deterministic order, so the allocator semantics and resource accounting (used, allocs map) remain unaffected. - Change type and intent: Enhancement/refactor of unit test stability — it tightens test synchronization to remove race-dependent assertions and ensure the Wait/notify mechanism is reliably exercised without modifying allocator logic. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>
This commit is contained in:
parent
1a6f3c4305
commit
26c86ec221
@ -96,22 +96,27 @@ func TestWait(t *testing.T) {
|
||||
a := NewFixedSizeAllocator[string](&Resource{100, 100, 100})
|
||||
allocated, _ := a.Allocate("a1", &Resource{100, 100, 100})
|
||||
assert.True(t, allocated)
|
||||
for i := 0; i < 100; i++ {
|
||||
go func(index int) {
|
||||
|
||||
waitCh := make(chan struct{})
|
||||
release := func() {
|
||||
<-waitCh
|
||||
for i := 0; i < 100; i++ {
|
||||
allocated, _ := a.Reallocate("a1", &Resource{-1, -1, -1})
|
||||
assert.Equal(t, true, allocated)
|
||||
}(i)
|
||||
}
|
||||
}
|
||||
|
||||
go release()
|
||||
|
||||
allocated, _ = a.Allocate("a2", &Resource{100, 100, 100})
|
||||
i := 1
|
||||
assert.False(t, allocated)
|
||||
close(waitCh) // start release a1
|
||||
|
||||
for !allocated {
|
||||
a.Wait()
|
||||
a.Wait() // alloc after wait
|
||||
allocated, _ = a.Allocate("a2", &Resource{100, 100, 100})
|
||||
i++
|
||||
}
|
||||
assert.True(t, allocated)
|
||||
assert.True(t, i < 100 && i > 1)
|
||||
}
|
||||
|
||||
func TestPhysicalAwareFixedSizeAllocator(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user