59f81a4a0d
we used to do something similar for puts, but that ended up hurting more than it helped. since deletes are best effort, we can do it here to kill long tails or unresponsive nodes. Change-Id: I89fd2d9dcf519d76c78ddad70bc419d1868d2df1
74 lines
1.1 KiB
Go
74 lines
1.1 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package groupcancel
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestContext_SuccessThreshold(t *testing.T) {
|
|
ctx, cancel := NewContext(context.Background(), 10, .5, 0)
|
|
defer cancel()
|
|
|
|
for i := 0; i < 4; i++ {
|
|
ctx.Success()
|
|
select {
|
|
case <-ctx.Done():
|
|
t.FailNow()
|
|
default:
|
|
}
|
|
}
|
|
|
|
ctx.Success()
|
|
<-ctx.Done()
|
|
}
|
|
|
|
func TestContext_FailThreshold(t *testing.T) {
|
|
ctx, cancel := NewContext(context.Background(), 10, .5, 0)
|
|
defer cancel()
|
|
|
|
for i := 0; i < 4; i++ {
|
|
ctx.Success()
|
|
select {
|
|
case <-ctx.Done():
|
|
t.FailNow()
|
|
default:
|
|
}
|
|
}
|
|
|
|
ctx.Failure()
|
|
ctx.Failure()
|
|
<-ctx.Done()
|
|
}
|
|
|
|
func TestContext_AllFailures(t *testing.T) {
|
|
ctx, cancel := NewContext(context.Background(), 10, .5, 0)
|
|
defer cancel()
|
|
|
|
for i := 0; i < 9; i++ {
|
|
ctx.Failure()
|
|
select {
|
|
case <-ctx.Done():
|
|
t.FailNow()
|
|
default:
|
|
}
|
|
}
|
|
|
|
ctx.Failure()
|
|
<-ctx.Done()
|
|
}
|
|
|
|
func TestContext_UseAfterDone(t *testing.T) {
|
|
ctx, cancel := NewContext(context.Background(), 10, .5, 0)
|
|
defer cancel()
|
|
|
|
for i := 0; i < 20; i++ {
|
|
ctx.Success()
|
|
ctx.Failure()
|
|
}
|
|
|
|
<-ctx.Done()
|
|
}
|