Skip to content

Commit

Permalink
Bug 1772416 - sleep in measure_associated_with_navigation_timing. r=s…
Browse files Browse the repository at this point in the history
…efeng

The root cause of the intermittent failure is that the test records one set of
PerformanceMarks, records another, and verifies the duration of the measures of
the second set are larger than the first set but they're unexpectedly equal.

I speculate this happens because either the test executes fast enough that the
clock doesn't increment or our precision reduction code (to mitigate against
timing attacks) is rounding the before/after values to the same value.

This solution is speculative because I was unable to reproduce the error
locally so need to test it on WPT CI. The solution may fail intermittently if we
don't sleep for long enough.

A more correct solution to this problem would be to mock the clock and
programmatically advance it but I didn't want to take the time. Another possible
solution, that is stable, is to change the assertions to `test_greater_or_equal`
but this could hide legitimate bugs, e.g. we accidentally return the same
PerformanceMeasure for both queries.

Differential Revision: https://phabricator.services.mozilla.com/D155420
  • Loading branch information
mcomella committed Aug 24, 2022
1 parent 2976331 commit 183a9d6
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
test_greater_than(0, context.getEntriesByName('negativeValue', 'measure')[0].duration, 'Measure of current mark to navigationStart should be negative value.');
test_equals(context.getEntriesByName('loadTime', 'measure')[0].duration + context.getEntriesByName('loadEventEnd2a', 'measure')[0].duration, context.getEntriesByName('nav2a', 'measure')[0].duration, 'loadTime plus loadEventEnd to a mark "a" should equal to navigationStart to "a".');

// We later assert that time has passed between setting one set of marks and another set.
// However, this assertion will fail if the test executes fast enough such that the marks occur
// at the same clock time. This is more likely in browsers such as Firefox that reduce the
// precision of the clock exposed through this API to mitigate timing attacks. To mitigate the
// test failure, we sleep.
sleep_milliseconds(1);

// Following cases test for scenarios that measure names are tied twice.
mark_names.forEach(function(name) {
context.mark(name);
Expand Down

0 comments on commit 183a9d6

Please sign in to comment.