Skip to content

Commit

Permalink
Fix new test
Browse files Browse the repository at this point in the history
  • Loading branch information
veqryn committed Dec 9, 2023
1 parent 0b75b69 commit 3500a29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type NotifierOptions struct {
// to bugsnag in parallel. It defaults to the number of CPU's.
// Bugs are placed on a buffered channel to be sent to bugsnag, in order
// to not block or delay the log call from returning. The bugs are then
// sent to bugsnag asynchronously by a number of workers equal to this int.
// sent to bugsnag synchronously by a number of workers equal to this int.
MaxNotifierConcurrency int
}

Expand Down
21 changes: 14 additions & 7 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestHandlerOverloaded(t *testing.T) {
Sessions: svr.URL,
},
}),
bugsCh: make(chan bugRecord),
bugsCh: make(chan bugRecord, 1),
workerWG: sync.WaitGroup{},
isClosed: atomic.Bool{},
}
Expand All @@ -143,18 +143,25 @@ func TestHandlerOverloaded(t *testing.T) {

log.Error("this will be sent to fake bugsnag")

log.Error("this should trigger an extra log line about handler/workers overloaded")
// Depending on race conditions and available threads, we may need to log twice to trigger it, as one may sit in the buffer
log.Error("this could trigger an extra log line about handler/workers overloaded")
log.Error("this definitely should trigger an extra log line about handler/workers overloaded")

// Flush the channel and workers
h.Close()

// level=ERROR msg="slog-bugsnag bug buffer full; increase max concurrency or decrease bugs" original="this should trigger an extra log line about handler/workers overloaded"
if len(tester.Records) != 3 {
t.Fatal("Expected 3 log records; Got:", tester.Records)
if len(tester.Records) < 4 {
t.Fatal("Expected at least 4 log records; Got:", tester.Records)
}

// Should be second record
if !strings.Contains(tester.string(1), "slog-bugsnag bug buffer full; increase max concurrency or decrease bugs") {
t.Error("Expected second log line about bug buffer full; Got:", tester)
var found bool
for idx := range tester.Records {
if strings.Contains(tester.string(idx), "slog-bugsnag bug buffer full; increase max concurrency or decrease bugs") {
found = true
}
}
if !found {
t.Error("Expected a log line about bug buffer full; Got:", tester.Records)
}
}

0 comments on commit 3500a29

Please sign in to comment.