2022-01-08 21:23:26 -08:00
|
|
|
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()))
|
|
|
|
|
2023-11-15 17:14:00 -08:00
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), time.Microsecond*5)
|
|
|
|
<-ctx.Done()
|
2022-01-08 21:23:26 -08:00
|
|
|
cancel()
|
|
|
|
assert.False(t, IsCanceledError(ctx.Err()))
|
|
|
|
|
|
|
|
assert.False(t, IsCanceledError(errors.New("test error")))
|
|
|
|
}
|