Skip to content

Commit

Permalink
Add some webhook_handler logic fixes and test
Browse files Browse the repository at this point in the history
  • Loading branch information
renatosaksanni committed Jun 24, 2024
1 parent 8814b58 commit 5e39b01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webhook_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ func (b *Bot) WebhookHandler() http.HandlerFunc {
case <-req.Context().Done():
b.error("some updates lost, ctx done")
return
default:
}

select {
case b.updates <- update:
case <-req.Context().Done():
b.error("failed to send update, ctx done")
}
}
}
1 change: 1 addition & 0 deletions webhook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestWebhookHandler_ContextDone(t *testing.T) {
case <-bot.updates:
t.Fatal("Did not expect update to be sent to bot.updates channel")
default:
// Expected outcome, context was cancelled before sending the update
}

if len(errorsHandler.errors) == 0 {
Expand Down

0 comments on commit 5e39b01

Please sign in to comment.