Skip to content

Commit 82d2738

Browse files
committed
Add some comments
1 parent e7b0a0d commit 82d2738

File tree

1 file changed

+88
-63
lines changed

1 file changed

+88
-63
lines changed

pkg/firedb/delta_test.go

Lines changed: 88 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -82,71 +82,96 @@ func TestDeltaSample(t *testing.T) {
8282
}, highest)
8383
require.Equal(t, highest, new)
8484

85-
new = []*schemav1.Sample{
86-
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
87-
{StacktraceID: 3, Values: []int64{1, 2, 3, 4}},
88-
}
89-
highest = deltaSamples(highest, new, idx)
90-
require.Equal(t, 2, len(highest))
91-
require.Equal(t, []*schemav1.Sample{
92-
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
93-
{StacktraceID: 3, Values: []int64{1, 2, 3, 4}},
94-
}, highest)
95-
require.Equal(t, []*schemav1.Sample{
96-
{StacktraceID: 2, Values: []int64{0, 0, 3, 4}},
97-
{StacktraceID: 3, Values: []int64{0, 0, 3, 4}},
98-
}, new)
85+
t.Run("same stacktraces, matching counter samples, matching gauge samples", func(t *testing.T) {
86+
new = []*schemav1.Sample{
87+
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
88+
{StacktraceID: 3, Values: []int64{1, 2, 3, 4}},
89+
}
90+
highest = deltaSamples(highest, new, idx)
91+
require.Equal(t, 2, len(highest))
92+
require.Equal(t, []*schemav1.Sample{
93+
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
94+
{StacktraceID: 3, Values: []int64{1, 2, 3, 4}},
95+
}, highest)
96+
require.Equal(t, []*schemav1.Sample{
97+
{StacktraceID: 2, Values: []int64{0, 0, 3, 4}},
98+
{StacktraceID: 3, Values: []int64{0, 0, 3, 4}},
99+
}, new)
100+
})
99101

100-
new = []*schemav1.Sample{
101-
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
102-
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
103-
}
104-
highest = deltaSamples(highest, new, idx)
105-
require.Equal(t, []*schemav1.Sample{
106-
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
107-
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
108-
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
109-
}, highest)
110-
require.Equal(t, []*schemav1.Sample{
111-
{StacktraceID: 3, Values: []int64{5, 0, 3, 4}},
112-
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
113-
}, new)
102+
t.Run("same stacktraces, matching counter samples, empty gauge samples", func(t *testing.T) {
103+
new = []*schemav1.Sample{
104+
{StacktraceID: 2, Values: []int64{1, 2, 0, 0}},
105+
{StacktraceID: 3, Values: []int64{1, 2, 0, 0}},
106+
}
107+
highest = deltaSamples(highest, new, idx)
108+
require.Equal(t, 2, len(highest))
109+
require.Equal(t, []*schemav1.Sample{
110+
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
111+
{StacktraceID: 3, Values: []int64{1, 2, 3, 4}},
112+
}, highest)
113+
require.Equal(t, []*schemav1.Sample{
114+
{StacktraceID: 2, Values: []int64{0, 0, 0, 0}},
115+
{StacktraceID: 3, Values: []int64{0, 0, 0, 0}},
116+
}, new)
117+
})
114118

115-
new = []*schemav1.Sample{
116-
{StacktraceID: 3, Values: []int64{1, 2, 3, 4}},
117-
{StacktraceID: 5, Values: []int64{0, 5, 3, 4}},
118-
}
119-
highest = deltaSamples(highest, new, idx)
120-
require.Equal(t, []*schemav1.Sample{
121-
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
122-
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
123-
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
124-
}, highest)
125-
require.Equal(t, []*schemav1.Sample{
126-
{StacktraceID: 3, Values: []int64{0, 0, 3, 4}},
127-
{StacktraceID: 5, Values: []int64{0, 0, 3, 4}},
128-
}, new)
119+
t.Run("new stacktrace, and increase counter in existing stacktrace", func(t *testing.T) {
120+
new = []*schemav1.Sample{
121+
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
122+
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
123+
}
124+
highest = deltaSamples(highest, new, idx)
125+
require.Equal(t, []*schemav1.Sample{
126+
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
127+
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
128+
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
129+
}, highest)
130+
require.Equal(t, []*schemav1.Sample{
131+
{StacktraceID: 3, Values: []int64{5, 0, 3, 4}},
132+
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
133+
}, new)
134+
})
129135

130-
new = []*schemav1.Sample{
131-
{StacktraceID: 0, Values: []int64{10, 20, 3, 4}},
132-
{StacktraceID: 1, Values: []int64{2, 3, 3, 4}},
133-
{StacktraceID: 7, Values: []int64{1, 1, 3, 4}},
134-
}
135-
highest = deltaSamples(highest, new, idx)
136-
sort.Slice(highest, func(i, j int) bool {
137-
return highest[i].StacktraceID < highest[j].StacktraceID
136+
t.Run("same stacktraces, counter samples resetting", func(t *testing.T) {
137+
new = []*schemav1.Sample{
138+
{StacktraceID: 3, Values: []int64{1, 2, 3, 4}},
139+
{StacktraceID: 5, Values: []int64{0, 5, 3, 4}},
140+
}
141+
highest = deltaSamples(highest, new, idx)
142+
require.Equal(t, []*schemav1.Sample{
143+
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
144+
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
145+
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
146+
}, highest)
147+
require.Equal(t, []*schemav1.Sample{
148+
{StacktraceID: 3, Values: []int64{1, 0, 3, 4}},
149+
{StacktraceID: 5, Values: []int64{0, 0, 3, 4}},
150+
}, new)
151+
})
152+
153+
t.Run("two new stacktraces, raise counters of existing stacktrace", func(t *testing.T) {
154+
new = []*schemav1.Sample{
155+
{StacktraceID: 0, Values: []int64{10, 20, 3, 4}},
156+
{StacktraceID: 1, Values: []int64{2, 3, 3, 4}},
157+
{StacktraceID: 7, Values: []int64{1, 1, 3, 4}},
158+
}
159+
highest = deltaSamples(highest, new, idx)
160+
sort.Slice(highest, func(i, j int) bool {
161+
return highest[i].StacktraceID < highest[j].StacktraceID
162+
})
163+
require.Equal(t, []*schemav1.Sample{
164+
{StacktraceID: 0, Values: []int64{10, 20, 3, 4}},
165+
{StacktraceID: 1, Values: []int64{2, 3, 3, 4}},
166+
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
167+
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
168+
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
169+
{StacktraceID: 7, Values: []int64{1, 1, 3, 4}},
170+
}, highest)
171+
require.Equal(t, []*schemav1.Sample{
172+
{StacktraceID: 0, Values: []int64{10, 20, 3, 4}},
173+
{StacktraceID: 1, Values: []int64{2, 3, 3, 4}},
174+
{StacktraceID: 7, Values: []int64{1, 1, 3, 4}},
175+
}, new)
138176
})
139-
require.Equal(t, []*schemav1.Sample{
140-
{StacktraceID: 0, Values: []int64{10, 20, 3, 4}},
141-
{StacktraceID: 1, Values: []int64{2, 3, 3, 4}},
142-
{StacktraceID: 2, Values: []int64{1, 2, 3, 4}},
143-
{StacktraceID: 3, Values: []int64{6, 2, 3, 4}},
144-
{StacktraceID: 5, Values: []int64{1, 5, 3, 4}},
145-
{StacktraceID: 7, Values: []int64{1, 1, 3, 4}},
146-
}, highest)
147-
require.Equal(t, []*schemav1.Sample{
148-
{StacktraceID: 0, Values: []int64{10, 20, 3, 4}},
149-
{StacktraceID: 1, Values: []int64{2, 3, 3, 4}},
150-
{StacktraceID: 7, Values: []int64{1, 1, 3, 4}},
151-
}, new)
152177
}

0 commit comments

Comments
 (0)