Skip to content

Commit

Permalink
fix flaky unit tests (#1421)
Browse files Browse the repository at this point in the history
* fix flaky unit test

* fix flaky instrumenter_test
  • Loading branch information
mariomac authored Dec 1, 2024
1 parent 4174fa5 commit 4ca0c48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
7 changes: 4 additions & 3 deletions pkg/export/otel/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,10 @@ func TestTraceSampling(t *testing.T) {
}

receiver.processSpans(exporter, spans, attrs, sampler)
// The result is likely 0,1,2 with 1/10th, but we don't want
// to maybe fail if it accidentally it randomly becomes 3
assert.GreaterOrEqual(t, 3, len(tr))
// The result is likely 0,1,2 with 1/10th, but since sampling
// it's a probabilistic matter, we don't want this test to become
// flaky as some of them could report even 4-5 samples
assert.GreaterOrEqual(t, 6, len(tr))
})
}

Expand Down
19 changes: 8 additions & 11 deletions pkg/internal/pipe/instrumenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,17 +599,14 @@ func TestSpanAttributeFilterNode(t *testing.T) {

// expect to receive only the records matching the Filters criteria
events := map[string]map[string]string{}
var event collector.MetricRecord
test.Eventually(t, testTimeout, func(tt require.TestingT) {
event = testutil.ReadChannel(t, tc.Records(), testTimeout)
require.Equal(tt, "http.server.request.duration", event.Name)
})
events[event.Attributes["url.path"]] = event.Attributes
test.Eventually(t, testTimeout, func(tt require.TestingT) {
event = testutil.ReadChannel(t, tc.Records(), testTimeout)
require.Equal(tt, "http.server.request.duration", event.Name)
})
events[event.Attributes["url.path"]] = event.Attributes
for i := 0; i < 10; i++ {
var event collector.MetricRecord
test.Eventually(t, testTimeout, func(tt require.TestingT) {
event = testutil.ReadChannel(t, tc.Records(), testTimeout)
require.Equal(tt, "http.server.request.duration", event.Name)
})
events[event.Attributes["url.path"]] = event.Attributes
}

assert.Equal(t, map[string]map[string]string{
"/user/1234": {
Expand Down

0 comments on commit 4ca0c48

Please sign in to comment.