From e584bde1bfbe97161ab2f7f995c3ec115ba107d3 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 25 Apr 2022 10:05:11 -0700 Subject: [PATCH] test: deal with test flakiness due to early setTimeout callback (#2657) 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: https://github.com/nodejs/node/issues/26578#issuecomment-473708703 Refs: #2647 --- test/instrumentation/span-compression.test.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/instrumentation/span-compression.test.js b/test/instrumentation/span-compression.test.js index ad56f6eb42..48c6eee22f 100644 --- a/test/instrumentation/span-compression.test.js +++ b/test/instrumentation/span-compression.test.js @@ -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) { @@ -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() }) @@ -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() })