MCPcopy
hub / github.com/grafana/tempo / TestResetPushBytesRequest

Function TestResetPushBytesRequest

pkg/ingest/encoding_test.go:118–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func TestResetPushBytesRequest(t *testing.T) {
119 // Create a request with all fields set to non-zero values
120 traces := []tempopb.PreallocBytes{
121 {Slice: []byte("trace1")},
122 {Slice: []byte("trace2")},
123 {Slice: []byte("trace3")},
124 }
125 ids := [][]byte{
126 []byte("id1"),
127 []byte("id2"),
128 []byte("id3"),
129 }
130 req := &tempopb.PushBytesRequest{
131 Traces: traces,
132 Ids: ids,
133 SkipMetricsGeneration: true,
134 }
135
136 resetPushBytesRequest(req)
137
138 // Verify all fields are properly reset
139 assert.NotNil(t, req.Traces, "Traces should not be nil")
140 assert.NotNil(t, req.Ids, "Ids should not be nil")
141 assert.Equal(t, 0, len(req.Traces), "Traces should be empty after reset")
142 assert.Equal(t, 0, len(req.Ids), "Ids should be empty after reset")
143 assert.Equal(t, false, req.SkipMetricsGeneration, "SkipMetricsGeneration should be reset to false")
144
145 // Verify slices are reused (not reallocated) by comparing pointers
146 originalTracesPtr := reflect.ValueOf(traces).Pointer()
147 newTracesPtr := reflect.ValueOf(req.Traces).Pointer()
148 assert.Equal(t, originalTracesPtr, newTracesPtr, "Traces slice should be reused, not reallocated")
149
150 originalIDsPtr := reflect.ValueOf(ids).Pointer()
151 newIDsPtr := reflect.ValueOf(req.Ids).Pointer()
152 assert.Equal(t, originalIDsPtr, newIDsPtr, "Ids slice should be reused, not reallocated")
153}
154
155// Helper function to generate a test trace
156func generateRequest(entries, lineLength int) *tempopb.PushBytesRequest {

Callers

nothing calls this directly

Calls 2

resetPushBytesRequestFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected