storj/internal/groupcancel/groupcancel_test.go
Jeff Wendling 59f81a4a0d groupcancel/ec delete: add a timeout based on completion times
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
2019-10-30 16:18:39 -06:00

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()
}