mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-15 17:42:24 +02:00
gofmt
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"context"
|
||||
"time"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestContextWithOptionalDeadline(t *testing.T) {
|
||||
@ -18,14 +18,14 @@ func TestContextWithOptionalDeadline(t *testing.T) {
|
||||
var cancellationError error
|
||||
go func() {
|
||||
select {
|
||||
case <- cctx.Done():
|
||||
case <-cctx.Done():
|
||||
receivedCancellation = time.Now()
|
||||
cancellationError = cctx.Err()
|
||||
case <- time.After(600*time.Millisecond):
|
||||
case <-time.After(600 * time.Millisecond):
|
||||
t.Fatalf("should have been cancelled by deadline")
|
||||
}
|
||||
}()
|
||||
time.Sleep(100*time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if !receivedCancellation.IsZero() {
|
||||
t.Fatalf("no enforcement means no cancellation")
|
||||
}
|
||||
@ -33,11 +33,11 @@ func TestContextWithOptionalDeadline(t *testing.T) {
|
||||
dl, ok := cctx.Deadline()
|
||||
require.False(t, ok)
|
||||
require.Zero(t, dl)
|
||||
enforceDeadline(begin.Add(200*time.Millisecond))
|
||||
enforceDeadline(begin.Add(200 * time.Millisecond))
|
||||
// second call must be ignored, i.e. we expect the deadline to be at begin+200ms, not begin+400ms
|
||||
enforceDeadline(begin.Add(400*time.Millisecond))
|
||||
enforceDeadline(begin.Add(400 * time.Millisecond))
|
||||
|
||||
time.Sleep(300*time.Millisecond) // 100ms margin for scheduler
|
||||
time.Sleep(300 * time.Millisecond) // 100ms margin for scheduler
|
||||
if receivedCancellation.Sub(begin) > 250*time.Millisecond {
|
||||
t.Fatalf("cancellation is beyond acceptable scheduler latency")
|
||||
}
|
||||
@ -47,7 +47,7 @@ func TestContextWithOptionalDeadline(t *testing.T) {
|
||||
func TestContextWithOptionalDeadlineNegativeDeadline(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cctx, enforceDeadline := ContextWithOptionalDeadline(ctx)
|
||||
enforceDeadline(time.Now().Add(-10*time.Second))
|
||||
enforceDeadline(time.Now().Add(-10 * time.Second))
|
||||
select {
|
||||
case <-cctx.Done():
|
||||
default:
|
||||
@ -62,10 +62,10 @@ func TestContextWithOptionalDeadlineParentCancellation(t *testing.T) {
|
||||
|
||||
// 0 ms
|
||||
start := time.Now()
|
||||
enforceDeadline(start.Add(400*time.Millisecond))
|
||||
time.Sleep(100*time.Millisecond)
|
||||
cancel() // cancel @ ~100ms
|
||||
time.Sleep(100*time.Millisecond) // give 100ms time to propagate cancel
|
||||
enforceDeadline(start.Add(400 * time.Millisecond))
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
cancel() // cancel @ ~100ms
|
||||
time.Sleep(100 * time.Millisecond) // give 100ms time to propagate cancel
|
||||
// @ ~200ms
|
||||
select {
|
||||
case <-cctx.Done():
|
||||
@ -81,4 +81,4 @@ func TestContextWithOptionalDeadlineValue(t *testing.T) {
|
||||
pctx := context.WithValue(context.Background(), "key", "value")
|
||||
cctx, _ := ContextWithOptionalDeadline(pctx)
|
||||
assert.Equal(t, "value", cctx.Value("key"))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user