Browse Source

refactor - remove ShrinkDeadline, it's the same as context.WithTimeout (#599)

Kevin Wan 4 năm trước cách đây
mục cha
commit
05e37ee20f
2 tập tin đã thay đổi với 0 bổ sung43 xóa
  1. 0 12
      core/contextx/deadline.go
  2. 0 31
      core/contextx/deadline_test.go

+ 0 - 12
core/contextx/deadline.go

@@ -1,12 +0,0 @@
-package contextx
-
-import (
-	"context"
-	"time"
-)
-
-// ShrinkDeadline returns a new Context with proper deadline base on the given ctx and timeout.
-// And returns a cancel function as well.
-func ShrinkDeadline(ctx context.Context, timeout time.Duration) (context.Context, func()) {
-	return context.WithTimeout(ctx, timeout)
-}

+ 0 - 31
core/contextx/deadline_test.go

@@ -1,31 +0,0 @@
-package contextx
-
-import (
-	"context"
-	"testing"
-	"time"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func TestShrinkDeadlineLess(t *testing.T) {
-	deadline := time.Now().Add(time.Second)
-	ctx, cancel := context.WithDeadline(context.Background(), deadline)
-	defer cancel()
-	ctx, cancel = ShrinkDeadline(ctx, time.Minute)
-	defer cancel()
-	dl, ok := ctx.Deadline()
-	assert.True(t, ok)
-	assert.Equal(t, deadline, dl)
-}
-
-func TestShrinkDeadlineMore(t *testing.T) {
-	deadline := time.Now().Add(time.Minute)
-	ctx, cancel := context.WithDeadline(context.Background(), deadline)
-	defer cancel()
-	ctx, cancel = ShrinkDeadline(ctx, time.Second)
-	defer cancel()
-	dl, ok := ctx.Deadline()
-	assert.True(t, ok)
-	assert.True(t, dl.Before(deadline))
-}