|
@@ -10,8 +10,10 @@ import (
|
|
|
|
|
|
func TestShrinkDeadlineLess(t *testing.T) {
|
|
func TestShrinkDeadlineLess(t *testing.T) {
|
|
deadline := time.Now().Add(time.Second)
|
|
deadline := time.Now().Add(time.Second)
|
|
- ctx, _ := context.WithDeadline(context.Background(), deadline)
|
|
|
|
- ctx, _ = ShrinkDeadline(ctx, time.Minute)
|
|
|
|
|
|
+ ctx, cancel := context.WithDeadline(context.Background(), deadline)
|
|
|
|
+ defer cancel()
|
|
|
|
+ ctx, cancel = ShrinkDeadline(ctx, time.Minute)
|
|
|
|
+ defer cancel()
|
|
dl, ok := ctx.Deadline()
|
|
dl, ok := ctx.Deadline()
|
|
assert.True(t, ok)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, deadline, dl)
|
|
assert.Equal(t, deadline, dl)
|
|
@@ -19,8 +21,10 @@ func TestShrinkDeadlineLess(t *testing.T) {
|
|
|
|
|
|
func TestShrinkDeadlineMore(t *testing.T) {
|
|
func TestShrinkDeadlineMore(t *testing.T) {
|
|
deadline := time.Now().Add(time.Minute)
|
|
deadline := time.Now().Add(time.Minute)
|
|
- ctx, _ := context.WithDeadline(context.Background(), deadline)
|
|
|
|
- ctx, _ = ShrinkDeadline(ctx, time.Second)
|
|
|
|
|
|
+ ctx, cancel := context.WithDeadline(context.Background(), deadline)
|
|
|
|
+ defer cancel()
|
|
|
|
+ ctx, cancel = ShrinkDeadline(ctx, time.Second)
|
|
|
|
+ defer cancel()
|
|
dl, ok := ctx.Deadline()
|
|
dl, ok := ctx.Deadline()
|
|
assert.True(t, ok)
|
|
assert.True(t, ok)
|
|
assert.True(t, dl.Before(deadline))
|
|
assert.True(t, dl.Before(deadline))
|