Merge pull request #4689 from hashicorp/backport/bosorawis-fix-eventing-for-context-deadline-exceeded/accurately-master-grub

This pull request was automerged via backport-assistant
pull/4690/head
hc-github-team-secure-boundary 2 years ago committed by GitHub
commit be19cc106a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

@ -6,6 +6,7 @@ package event
import ( import (
"context" "context"
"testing" "testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -44,6 +45,28 @@ func Test_newSendCtx(t *testing.T) {
}(), }(),
wantCancel: true, 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", name: "no-info",
ctx: context.Background(), ctx: context.Background(),
@ -65,6 +88,7 @@ func Test_newSendCtx(t *testing.T) {
ctx, cancel := newSendCtx(tt.ctx) ctx, cancel := newSendCtx(tt.ctx)
require.NotNil(ctx) require.NotNil(ctx)
assert.True(ctx.Err() != context.Canceled) assert.True(ctx.Err() != context.Canceled)
assert.True(ctx.Err() != context.DeadlineExceeded)
if tt.wantCancel { if tt.wantCancel {
require.NotNil(cancel) require.NotNil(cancel)
} else { } else {

Loading…
Cancel
Save