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"
|
||||
@@ -32,30 +33,39 @@ func TestAggregatorMergesByOriginAndPreservesFirstOccurrenceOrder(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAggregatorEnforcesWarningBoundAndTruncatesOnlyNonWarnings(t *testing.T) {
|
||||
warnings := Aggregator{}
|
||||
for index := 0; index < MaxWarningGroups; index++ {
|
||||
group := groupForAggregation("scope", "message", contracts.DiagnosticDispositionWarning, contracts.DiagnosticCategoryFallback, "module")
|
||||
group.ReasonCode = "warning-" + string(rune('a'+index))
|
||||
if err := warnings.Add(group); err != nil {
|
||||
t.Fatalf("warning Add(%d) error = %v", index, err)
|
||||
func TestAggregatorRetainsManyWarningAndNonWarningGroups(t *testing.T) {
|
||||
aggregator := Aggregator{}
|
||||
for index := 0; index < 400; index++ {
|
||||
for _, kind := range []struct {
|
||||
disposition contracts.DiagnosticDisposition
|
||||
category contracts.DiagnosticCategory
|
||||
}{
|
||||
{contracts.DiagnosticDispositionWarning, contracts.DiagnosticCategoryFallback},
|
||||
{contracts.DiagnosticDispositionAdvisory, contracts.DiagnosticCategoryDataQuality},
|
||||
} {
|
||||
group := groupForAggregation("scope", "message", kind.disposition, kind.category, "module")
|
||||
group.ReasonCode = fmt.Sprintf("reason-%d", index)
|
||||
if err := aggregator.Add(group); err != nil {
|
||||
t.Fatalf("Add(%d) error = %v", index, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := warnings.Add(groupForAggregation("overflow", "overflow", contracts.DiagnosticDispositionWarning, contracts.DiagnosticCategoryFallback, "overflow")); err == nil {
|
||||
t.Fatal("warning overflow error = nil, want error")
|
||||
if got := len(aggregator.Collection().Groups); got != 800 {
|
||||
t.Fatalf("group count = %d, want 800", got)
|
||||
}
|
||||
}
|
||||
|
||||
nonWarnings := Aggregator{}
|
||||
for index := 0; index < MaxNonWarningGroups+3; index++ {
|
||||
group := groupForAggregation("scope", "message", contracts.DiagnosticDispositionAdvisory, contracts.DiagnosticCategoryDataQuality, "module")
|
||||
group.ReasonCode = "advisory-" + string(rune('a'+index))
|
||||
if err := nonWarnings.Add(group); err != nil {
|
||||
t.Fatalf("non-warning Add(%d) error = %v", index, err)
|
||||
func TestAggregatorSamplesRepeatedOccurrences(t *testing.T) {
|
||||
aggregator := Aggregator{}
|
||||
for i := 0; i < 5; i++ {
|
||||
group := groupForAggregation(fmt.Sprintf("scope-%d", i), "message", contracts.DiagnosticDispositionAdvisory, contracts.DiagnosticCategoryDataQuality, "module")
|
||||
if err := aggregator.Add(group); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
collection := nonWarnings.Collection()
|
||||
if len(collection.Groups) != MaxNonWarningGroups || !collection.Truncated || collection.UnrepresentedOccurrenceCount != 3 {
|
||||
t.Fatalf("collection = %#v, want bounded non-warning groups and three unrepresented occurrences", collection)
|
||||
groups := aggregator.Collection().Groups
|
||||
if len(groups) != 1 || groups[0].OccurrenceCount != 5 || len(groups[0].Samples) != 3 || groups[0].OmittedSampleCount != 2 {
|
||||
t.Fatalf("groups = %#v, want five occurrences and three samples", groups)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user