Handle context cancellations and avoid logged errors.

This commit is contained in:
mikestefanello 2022-01-09 00:23:26 -05:00
parent 0f7da0864e
commit acd38c8205
8 changed files with 83 additions and 35 deletions

24
context/context_test.go Normal file
View file

@ -0,0 +1,24 @@
package context
import (
"context"
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestIsCanceled(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
assert.False(t, IsCanceledError(ctx.Err()))
cancel()
assert.True(t, IsCanceledError(ctx.Err()))
ctx, cancel = context.WithTimeout(context.Background(), time.Microsecond)
time.Sleep(time.Microsecond * 2)
cancel()
assert.False(t, IsCanceledError(ctx.Err()))
assert.False(t, IsCanceledError(errors.New("test error")))
}