Commit 5083fb9d authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

sensors: Rewrite the frequency hint test.

This test has been flaky on the Mac bots for a very long time. Previous
efforts such as r770328 ('sensors: Make frequency hint test wait for another
slow sensor "tick"') did improve things a bit, but the flakiness has not
been fully fixed.

The problem is that our mock platform sensor dispatches sensor reading
notifications via window.setInterval(), and the actual period of the
callback can vary significantly, to the point where we cannot make any
assumptions about how precise it will be. The Mac bots in particular seem to
have big deviations in the timer's precision.

Consequently, we also cannot assume a faster sensor will really receive more
"reading" events than a slower one, or how long it will take for it to
happen.

Make the test deterministic at the expense of testing a less "real" use
case: instead of comparing how many times each sensor receives a "reading"
event, we just check that MockSensor.getSamplingFrequency() is adjusted
accordingly depending on which sensors are active.

Bug: 731018
Change-Id: Idc994d7e7d1cfb30d7c4e2f4b285494faff7160c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401139
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805674}
parent 2b0d6a36
...@@ -5799,12 +5799,6 @@ crbug.com/1003055 external/wpt/css/css-scroll-snap/scroll-target-align-002.html ...@@ -5799,12 +5799,6 @@ crbug.com/1003055 external/wpt/css/css-scroll-snap/scroll-target-align-002.html
crbug.com/1003055 external/wpt/css/css-scroll-snap/scroll-target-snap-001.html [ Failure ] crbug.com/1003055 external/wpt/css/css-scroll-snap/scroll-target-snap-001.html [ Failure ]
crbug.com/1003055 external/wpt/css/css-scroll-snap/scroll-target-snap-002.html [ Failure ] crbug.com/1003055 external/wpt/css/css-scroll-snap/scroll-target-snap-002.html [ Failure ]
# Sheriff 2019-09-12
crbug.com/731018 [ Mac ] external/wpt/accelerometer/Accelerometer.https.html [ Pass Failure ]
crbug.com/731018 [ Mac ] external/wpt/gyroscope/Gyroscope.https.html [ Pass Failure ]
crbug.com/731018 [ Mac ] external/wpt/orientation-sensor/AbsoluteOrientationSensor.https.html [ Pass Failure ]
crbug.com/731018 [ Mac ] external/wpt/orientation-sensor/RelativeOrientationSensor.https.html [ Pass Failure ]
# Sheriff 2019-09-20 # Sheriff 2019-09-20
crbug.com/1005128 crypto/subtle/abandon-crypto-operation2.html [ Pass Crash ] crbug.com/1005128 crypto/subtle/abandon-crypto-operation2.html [ Pass Crash ]
......
...@@ -371,47 +371,40 @@ function runGenericSensorTests(sensorName, ...@@ -371,47 +371,40 @@ function runGenericSensorTests(sensorName,
sensor_test(async (t, sensorProvider) => { sensor_test(async (t, sensorProvider) => {
assert_implements(sensorName in self, `${sensorName} is not supported.`); assert_implements(sensorName in self, `${sensorName} is not supported.`);
const fastSensor = new sensorType({frequency: 60});
const fastSensor = new sensorType({ frequency: 60 });
t.add_cleanup(() => { fastSensor.stop(); });
let eventWatcher = new EventWatcher(t, fastSensor, "activate");
fastSensor.start(); fastSensor.start();
// Wait for |fastSensor| to be activated so that the call to
// getSamplingFrequency() below works.
await eventWatcher.wait_for("activate");
const mockSensor = await sensorProvider.getCreatedSensor(sensorName); const mockSensor = await sensorProvider.getCreatedSensor(sensorName);
await mockSensor.setSensorReading(readings); await mockSensor.setSensorReading(readings);
return new Promise((resolve, reject) => { // We need |fastSensorFrequency| because 60Hz might be higher than a sensor
let fastSensorNotifiedCounter = 0; // type's maximum allowed frequency.
let slowSensorNotifiedCounter = 0; const fastSensorFrequency = mockSensor.getSamplingFrequency();
const slowSensorFrequency = fastSensorFrequency * 0.25;
fastSensor.onreading = () => {
if (fastSensorNotifiedCounter === 0) { const slowSensor = new sensorType({ frequency: slowSensorFrequency });
// For Magnetometer and ALS, the maximum frequency is less than 60Hz t.add_cleanup(() => { slowSensor.stop(); });
// we make "slow" sensor 4 times slower than the actual applied eventWatcher = new EventWatcher(t, slowSensor, "activate");
// frequency, so that the "fast" sensor will immediately overtake it slowSensor.start();
// despite the notification adjustments.
const slowFrequency = mockSensor.getSamplingFrequency() * 0.25; // Wait for |slowSensor| to be activated before we check if the mock
const slowSensor = new sensorType({frequency: slowFrequency}); // platform sensor's sampling frequency has changed.
slowSensor.onreading = () => { await eventWatcher.wait_for("activate");
// Skip the initial notification that always comes immediately. assert_equals(mockSensor.getSamplingFrequency(), fastSensorFrequency);
if (slowSensorNotifiedCounter === 2) {
fastSensor.stop(); // Now stop |fastSensor| and verify that the sampling frequency has dropped
slowSensor.stop(); // to the one |slowSensor| had requested.
fastSensor.stop();
try { return t.step_wait(() => {
assert_greater_than(fastSensorNotifiedCounter, 3, return mockSensor.getSamplingFrequency() === slowSensorFrequency;
"Fast sensor overtakes the slow one"); }, "Sampling frequency has dropped to slowSensor's requested frequency");
resolve();
} catch (e) {
reject(e);
}
}
slowSensorNotifiedCounter++;
}
slowSensor.onerror = reject;
slowSensor.start();
}
fastSensorNotifiedCounter++;
}
fastSensor.onerror = reject;
});
}, `${sensorName}: frequency hint works.`); }, `${sensorName}: frequency hint works.`);
// Re-enable after https://github.com/w3c/sensors/issues/361 is fixed. // Re-enable after https://github.com/w3c/sensors/issues/361 is fixed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment