Skip to content

Commit

Permalink
test: deal with test flakiness due to early setTimeout callback (#2657)
Browse files Browse the repository at this point in the history
These two 'span.composite.sum > 30' tests have been flaky in CI. A recent
failure shows a value of `29.699`. The theory is that this is due to
the setTimeout calls firing slightly sooner than 10ms as discussed at:
nodejs/node#26578 (comment)

Refs: #2647
  • Loading branch information
trentm authored Apr 25, 2022
1 parent 9bdbd07 commit e584bde
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/instrumentation/span-compression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const destinationContext = {
}
}

// `setTimeout` precision is ~1ms. It can fire its callback up to a millisecond
// early. Comparisons on the minimum time for an action using setTimeout should
// allow for this.
const SET_TIMEOUT_EPSILON_MS = 1

tape.test('integration/end-to-end span compression tests', function (suite) {
suite.test('exact match compression', function (t) {
resetAgent(function (data) {
Expand All @@ -31,7 +36,8 @@ tape.test('integration/end-to-end span compression tests', function (suite) {
t.equals(span.name, 'name1')
t.equals(span.composite.compression_strategy, constants.STRATEGY_EXACT_MATCH)
t.equals(span.composite.count, 3)
t.true(span.composite.sum > 30)
t.true(span.composite.sum > 30 - (3 * SET_TIMEOUT_EPSILON_MS),
`span.composite.sum > ~30: ${span.composite.sum}`)
t.equals(span.duration, (finalSpan._endTimestamp - firstSpan.timestamp) / 1000)
t.end()
})
Expand Down Expand Up @@ -73,7 +79,8 @@ tape.test('integration/end-to-end span compression tests', function (suite) {
t.equals(span.name, 'Calls to foo')
t.equals(span.composite.compression_strategy, constants.STRATEGY_SAME_KIND)
t.equals(span.composite.count, 3)
t.true(span.composite.sum > 30, `span.composite.sum > 30: ${span.composite.sum}`)
t.true(span.composite.sum > 30 - (3 * SET_TIMEOUT_EPSILON_MS),
`span.composite.sum > ~30: ${span.composite.sum}`)
t.equals(span.duration, (finalSpan._endTimestamp - firstSpan.timestamp) / 1000)
t.end()
})
Expand Down

0 comments on commit e584bde

Please sign in to comment.