backport of commit b67338b265

pull/4689/head
Sorawis Nilparuk 2 years ago
parent 1a48fe5398
commit b9bd0578de

@ -368,7 +368,7 @@ func newSendCtx(ctx context.Context) (context.Context, context.CancelFunc) {
switch {
case ctx == nil:
return context.Background(), nil
case ctx.Err() == context.Canceled:
case ctx.Err() == context.Canceled || ctx.Err() == context.DeadlineExceeded:
sendCtx, sendCancel = context.WithTimeout(context.Background(), cancelledSendTimeout)
info, ok := RequestInfoFromContext(ctx)
if ok {

@ -6,6 +6,7 @@ package event
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -44,6 +45,28 @@ func Test_newSendCtx(t *testing.T) {
}(),
wantCancel: true,
},
{
name: "deadline-exceeded-with-info",
ctx: func() context.Context {
var err error
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-1*time.Millisecond))
defer cancel()
ctx, err = NewRequestInfoContext(ctx, testInfo)
require.NoError(t, err)
return ctx
}(),
wantCancel: true,
wantInfo: true,
},
{
name: "deadline-exceeded-no-info",
ctx: func() context.Context {
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-1*time.Millisecond))
defer cancel()
return ctx
}(),
wantCancel: true,
},
{
name: "no-info",
ctx: context.Background(),

Loading…
Cancel
Save