Shutdown metrics server when listener exits (#3445)

This commit is contained in:
Nikola Jokic
2024-04-16 21:29:03 +02:00
committed by GitHub
parent 4ee49fee14
commit f965dfef73
4 changed files with 14 additions and 7 deletions

View File

@@ -174,8 +174,8 @@ func (l *Listener) Listen(ctx context.Context, handler Handler) error {
continue
}
// New context is created to avoid cancelation during message handling.
if err := l.handleMessage(context.Background(), handler, msg); err != nil {
// Remove cancellation from the context to avoid cancelling the message handling.
if err := l.handleMessage(context.WithoutCancel(ctx), handler, msg); err != nil {
return fmt.Errorf("failed to handle message: %w", err)
}
}

View File

@@ -484,8 +484,8 @@ func TestListener_Listen(t *testing.T) {
).
Once()
// Ensure delete message is called with background context
client.On("DeleteMessage", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
// Ensure delete message is called without cancel
client.On("DeleteMessage", context.WithoutCancel(ctx), mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
config.Client = client