Retain all diagnostic groups without capacity caps
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package diagnostics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
@@ -33,7 +34,7 @@ func TestCollectorCountsOccurrencesAndRetainsDistinctSamplesInOrder(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectorSeparatesGroupsAndRejectsInvalidOrExcessiveGroups(t *testing.T) {
|
||||
func TestCollectorSeparatesGroupsAndRejectsInvalidGroups(t *testing.T) {
|
||||
collector := NewCollector()
|
||||
if err := collector.Add(advisory("one", "first")); err != nil {
|
||||
t.Fatalf("Add() error = %v", err)
|
||||
@@ -54,16 +55,16 @@ func TestCollectorSeparatesGroupsAndRejectsInvalidOrExcessiveGroups(t *testing.T
|
||||
t.Fatal("Add() error = nil, want invalid diagnostic error")
|
||||
}
|
||||
|
||||
limited := NewCollector()
|
||||
for index := 0; index < contracts.MaxProducerDiagnosticGroups; index++ {
|
||||
many := NewCollector()
|
||||
for index := 0; index < 400; index++ {
|
||||
diagnostic := advisory("scope", "message")
|
||||
diagnostic.ReasonCode = "reason-" + string(rune('a'+index))
|
||||
if err := limited.Add(diagnostic); err != nil {
|
||||
diagnostic.ReasonCode = fmt.Sprintf("reason-%d", index)
|
||||
if err := many.Add(diagnostic); err != nil {
|
||||
t.Fatalf("Add(%d) error = %v", index, err)
|
||||
}
|
||||
}
|
||||
if err := limited.Add(advisory("overflow", "overflow")); err == nil {
|
||||
t.Fatal("Add() error = nil, want local group limit error")
|
||||
if got := len(many.Diagnostics()); got != 400 {
|
||||
t.Fatalf("group count = %d, want 400", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +81,22 @@ func TestCollectorReturnsIndependentSnapshots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectorRejectsOccurrenceOverflow(t *testing.T) {
|
||||
collector := NewCollector()
|
||||
first := advisory("scope", "message")
|
||||
first.OccurrenceCount = maximumInt()
|
||||
first.OmittedSampleCount = maximumInt() - 1
|
||||
if err := collector.Add(first); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := collector.Add(advisory("other", "message")); err == nil {
|
||||
t.Fatal("Add() accepted occurrence count overflow")
|
||||
}
|
||||
if got := collector.Diagnostics(); len(got) != 1 || got[0].OccurrenceCount != maximumInt() {
|
||||
t.Fatalf("collector changed after overflow: %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func advisory(scope string, message string) contracts.ProducerDiagnostic {
|
||||
return contracts.ProducerDiagnostic{
|
||||
Disposition: contracts.DiagnosticDispositionAdvisory,
|
||||
|
||||
Reference in New Issue
Block a user