Skip to content

Commit

Permalink
filters/tracing: add allocations test for stateBagToTag (#2779)
Browse files Browse the repository at this point in the history
Followup on #2775

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Dec 6, 2023
1 parent 4502bb6 commit 5847d52
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions filters/tracing/statebagtotag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func TestStateBagToTag(t *testing.T) {

span := tracingtest.NewSpan("start_span")
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span))
ctx := &filtertest.Context{FRequest: req, FStateBag: make(map[string]interface{})}
ctx.StateBag()["item"] = "val"
ctx := &filtertest.Context{FRequest: req, FStateBag: map[string]interface{}{"item": "val"}}

f, err := NewStateBagToTag().CreateFilter([]interface{}{"item", "tag"})
require.NoError(t, err)
Expand All @@ -29,6 +28,24 @@ func TestStateBagToTag(t *testing.T) {
assert.Equal(t, "val", span.Tags["tag"])
}

func TestStateBagToTagAllocs(t *testing.T) {
req := &http.Request{Header: http.Header{}}

span := tracingtest.NewSpan("start_span")
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span))
ctx := &filtertest.Context{FRequest: req, FStateBag: map[string]interface{}{"item": "val"}}

f, err := NewStateBagToTag().CreateFilter([]interface{}{"item", "tag"})
require.NoError(t, err)

allocs := testing.AllocsPerRun(100, func() {
f.Request(ctx)
})
if allocs != 0.0 {
t.Errorf("Expected zero allocations, got %f", allocs)
}
}

func TestStateBagToTag_CreateFilter(t *testing.T) {
for _, ti := range []struct {
msg string
Expand Down

0 comments on commit 5847d52

Please sign in to comment.