mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
lib/pool: fix unreliable TestPoolMaxBufferMemory test
This turned out to be a problem in the tests. The tests used to do 1. allocate 2. increment 3. free 4. decrement But if one goroutine had just completed 2 and another had just completed 3 then this can cause the test to register too many allocations. This was fixed by doing the test in this order instead: 1. allocate 2. increment 3. decrement 4. free The 4 operations are atomic. Fixes #8813
This commit is contained in:
@@ -288,22 +288,24 @@ func TestPoolMaxBufferMemory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
)
|
||||
for i := 0; i < 20; i++ {
|
||||
const trials = 50
|
||||
for i := range trials {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if i < 4 {
|
||||
buf := bp.GetN(i + 1)
|
||||
countBuf(i + 1)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if i < trials/2 {
|
||||
n := i%4 + 1
|
||||
buf := bp.GetN(n)
|
||||
countBuf(n)
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
countBuf(-n)
|
||||
bp.PutN(buf)
|
||||
countBuf(-(i + 1))
|
||||
} else {
|
||||
buf := bp.Get()
|
||||
countBuf(1)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
bp.Put(buf)
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
countBuf(-1)
|
||||
bp.Put(buf)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user