mirror of
https://github.com/rclone/rclone.git
synced 2026-03-01 19:01:11 +00:00
lib/pool: fix flaky test which was causing timeouts
This puts a limit on the number of allocation failures in a row which stops the test timing out as the exponential backoffs get very large.
This commit is contained in:
@@ -16,16 +16,23 @@ import (
|
||||
|
||||
// makes the allocations be unreliable
|
||||
func makeUnreliable(bp *Pool) {
|
||||
const maxFailsInARow = 10
|
||||
var allocFails int
|
||||
bp.alloc = func(size int) ([]byte, error) {
|
||||
if rand.Intn(3) != 0 {
|
||||
if rand.Intn(3) != 0 && allocFails < maxFailsInARow {
|
||||
allocFails++
|
||||
return nil, errors.New("failed to allocate memory")
|
||||
}
|
||||
allocFails = 0
|
||||
return make([]byte, size), nil
|
||||
}
|
||||
var freeFails int
|
||||
bp.free = func(b []byte) error {
|
||||
if rand.Intn(3) != 0 {
|
||||
if rand.Intn(3) != 0 && freeFails < maxFailsInARow {
|
||||
freeFails++
|
||||
return errors.New("failed to free memory")
|
||||
}
|
||||
freeFails = 0
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user