Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinburkesegment committed Dec 10, 2024
1 parent 53208e5 commit fd3ce25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
16 changes: 13 additions & 3 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,20 @@ func (eng *Engine) measure(t time.Time, name string, value interface{}, ftype Fi
eng.once.Do(func() {
vsn := strings.TrimPrefix(runtime.Version(), "go")
parts := strings.Split(vsn, ".")
// this filters out weird compiled Go versions like tip.
// older Go version might be "go1.13"
// this filters out weird compiled Go versions like tip. len(parts)
// may equal 2 because older Go version might be "go1.13"
if len(parts) == 2 || len(parts) == 3 {
eng.measureOne(t, "go_version", 1, Gauge, []Tag{{"go_version", vsn}}...)
eng.Handler.HandleMeasures(t, Measure{

Name: "go_version",
Fields: []Field{{
Name: "go_version",
Value: intValue(1),
}},
Tags: []Tag{
{"go_version", vsn},
},
})
}
})
}
Expand Down
18 changes: 16 additions & 2 deletions netstats/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,25 @@ func TestListenerError(t *testing.T) {
vsn := strings.TrimPrefix(runtime.Version(), "go")
parts := strings.Split(vsn, ".")
measures := h.Measures()
measurePassed := false
if len(parts) == 2 || len(parts) == 3 {
if len(measures) != 1+1 {
t.Fatalf("expecting to get %d metrics, got back %d: %v", 1+1, len(measures), measures)
for _, measure := range measures {
if measure.Name != "go_version" {
continue
}
for _, tag := range measure.Tags {
if tag.Name != "go_version" {
continue
}
if tag.Value == vsn {
measurePassed = true
}
}
}
}
if !measurePassed {
t.Errorf("did not find correct tag for measure: %#v\n", measures)
}
var foundMetric stats.Measure
for i := range measures {
if measures[i].Name == "netstats.test.conn.error" {
Expand Down

0 comments on commit fd3ce25

Please sign in to comment.