Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
fix config_test to run in any order. (#1194)
Browse files Browse the repository at this point in the history
- fixes #1193
  • Loading branch information
rghetia authored Feb 2, 2020
1 parent d851005 commit d835ff8
Showing 1 changed file with 61 additions and 41 deletions.
102 changes: 61 additions & 41 deletions trace/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,69 +20,89 @@ import (
)

func TestApplyConfig(t *testing.T) {
testCfgs := []Config{
{},
cfg := config.Load().(*Config)
defaultCfg := Config{
DefaultSampler: cfg.DefaultSampler,
IDGenerator: cfg.IDGenerator,
MaxAttributesPerSpan: DefaultMaxAttributesPerSpan,
MaxAnnotationEventsPerSpan: DefaultMaxAnnotationEventsPerSpan,
MaxMessageEventsPerSpan: DefaultMaxMessageEventsPerSpan,
MaxLinksPerSpan: DefaultMaxLinksPerSpan,
}
testCases := []struct {
name string
newCfg Config
wantCfg Config
}{
{
MaxAttributesPerSpan: 1,
MaxAnnotationEventsPerSpan: 2,
MaxMessageEventsPerSpan: 3,
MaxLinksPerSpan: 4,
name: "Initialize to default config",
newCfg: defaultCfg,
wantCfg: defaultCfg,
},
{
MaxAttributesPerSpan: -1,
MaxAnnotationEventsPerSpan: 3,
MaxMessageEventsPerSpan: -3,
MaxLinksPerSpan: 5,
}}
cfg := config.Load().(*Config)
wantCfgs := []Config{
{
DefaultSampler: cfg.DefaultSampler,
IDGenerator: cfg.IDGenerator,
MaxAttributesPerSpan: DefaultMaxAttributesPerSpan,
MaxAnnotationEventsPerSpan: DefaultMaxAnnotationEventsPerSpan,
MaxMessageEventsPerSpan: DefaultMaxMessageEventsPerSpan,
MaxLinksPerSpan: DefaultMaxLinksPerSpan,
name: "Empty Config",
newCfg: Config{},
wantCfg: defaultCfg,
},
{
DefaultSampler: cfg.DefaultSampler,
IDGenerator: cfg.IDGenerator,
MaxAttributesPerSpan: 1,
MaxAnnotationEventsPerSpan: 2,
MaxMessageEventsPerSpan: 3,
MaxLinksPerSpan: 4,
name: "Valid non-default config",
newCfg: Config{
MaxAttributesPerSpan: 1,
MaxAnnotationEventsPerSpan: 2,
MaxMessageEventsPerSpan: 3,
MaxLinksPerSpan: 4,
},
wantCfg: Config{
DefaultSampler: cfg.DefaultSampler,
IDGenerator: cfg.IDGenerator,
MaxAttributesPerSpan: 1,
MaxAnnotationEventsPerSpan: 2,
MaxMessageEventsPerSpan: 3,
MaxLinksPerSpan: 4,
},
},
{
DefaultSampler: cfg.DefaultSampler,
IDGenerator: cfg.IDGenerator,
MaxAttributesPerSpan: 1,
MaxAnnotationEventsPerSpan: 3,
MaxMessageEventsPerSpan: 3,
MaxLinksPerSpan: 5,
}}
name: "Partially invalid config",
newCfg: Config{
MaxAttributesPerSpan: -1,
MaxAnnotationEventsPerSpan: 3,
MaxMessageEventsPerSpan: -3,
MaxLinksPerSpan: 5,
},
wantCfg: Config{
DefaultSampler: cfg.DefaultSampler,
IDGenerator: cfg.IDGenerator,
MaxAttributesPerSpan: 1,
MaxAnnotationEventsPerSpan: 3,
MaxMessageEventsPerSpan: 3,
MaxLinksPerSpan: 5,
},
},
}

for i, newCfg := range testCfgs {
for i, tt := range testCases {
newCfg := tt.newCfg
ApplyConfig(newCfg)
gotCfg := config.Load().(*Config)
wantCfg := wantCfgs[i]
wantCfg := tt.wantCfg

if got, want := reflect.ValueOf(gotCfg.DefaultSampler).Pointer(), reflect.ValueOf(wantCfg.DefaultSampler).Pointer(); got != want {
t.Fatalf("testId = %d config.DefaultSampler = %#v; want %#v", i, got, want)
t.Fatalf("testId = %d, testName = %s: config.DefaultSampler = %#v; want %#v", i, tt.name, got, want)
}
if got, want := gotCfg.IDGenerator, wantCfg.IDGenerator; got != want {
t.Fatalf("testId = %d config.IDGenerator = %#v; want %#v", i, got, want)
t.Fatalf("testId = %d, testName = %s: config.IDGenerator = %#v; want %#v", i, tt.name, got, want)
}
if got, want := gotCfg.MaxAttributesPerSpan, wantCfg.MaxAttributesPerSpan; got != want {
t.Fatalf("testId = %d config.MaxAttributesPerSpan = %#v; want %#v", i, got, want)
t.Fatalf("testId = %d, testName = %s: config.MaxAttributesPerSpan = %#v; want %#v", i, tt.name, got, want)
}
if got, want := gotCfg.MaxLinksPerSpan, wantCfg.MaxLinksPerSpan; got != want {
t.Fatalf("testId = %d config.MaxLinksPerSpan = %#v; want %#v", i, got, want)
t.Fatalf("testId = %d, testName = %s: config.MaxLinksPerSpan = %#v; want %#v", i, tt.name, got, want)
}
if got, want := gotCfg.MaxAnnotationEventsPerSpan, wantCfg.MaxAnnotationEventsPerSpan; got != want {
t.Fatalf("testId = %d config.MaxAnnotationEventsPerSpan = %#v; want %#v", i, got, want)
t.Fatalf("testId = %d, testName = %s: config.MaxAnnotationEventsPerSpan = %#v; want %#v", i, tt.name, got, want)
}
if got, want := gotCfg.MaxMessageEventsPerSpan, wantCfg.MaxMessageEventsPerSpan; got != want {
t.Fatalf("testId = %d config.MaxMessageEventsPerSpan = %#v; want %#v", i, got, want)
t.Fatalf("testId = %d, testName = %s: config.MaxMessageEventsPerSpan = %#v; want %#v", i, tt.name, got, want)
}

}
Expand Down

0 comments on commit d835ff8

Please sign in to comment.