1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// META: script=/resources/test-only-api.js
// META: script=resources/pressure-helpers.js
'use strict';
pressure_test(async (t, mockPressureService) => {
const pressureChanges = await new Promise(async resolve => {
const observer_changes = [];
let n = 0;
const observer = new PressureObserver(changes => {
observer_changes.push(changes);
if (++n === 2)
resolve(observer_changes);
}, {sampleRate: 5.0});
observer.observe('cpu');
const updatesDelivered = mockPressureService.updatesDelivered();
mockPressureService.setPressureUpdate('critical');
mockPressureService.startPlatformCollector(/*sampleRate*/ 5.0);
// Deliver 2 updates.
await t.step_wait(
() => mockPressureService.updatesDelivered() >= (updatesDelivered + 2),
'Wait for more than one update to be delivered to the observer');
mockPressureService.setPressureUpdate('nominal');
// Deliver more updates, |resolve()| will be called when the new pressure
// state reaches PressureObserver and its callback is invoked
// for the second time.
});
assert_equals(pressureChanges.length, 2);
assert_equals(pressureChanges[0][0].state, 'critical');
assert_equals(pressureChanges[1][0].state, 'nominal');
}, 'Changes that fail the "has change in data" test are discarded.');
pressure_test(async (t, mockPressureService) => {
const pressureChanges = await new Promise(async resolve => {
const observer_changes = [];
let n = 0;
const observer = new PressureObserver(changes => {
observer_changes.push(changes);
if (++n === 2)
resolve(observer_changes);
}, {sampleRate: 5.0});
observer.observe('cpu');
const updatesDelivered = mockPressureService.updatesDelivered();
mockPressureService.setPressureUpdate('critical', ['thermal']);
mockPressureService.startPlatformCollector(/*sampleRate*/ 5.0);
// Deliver 2 updates.
await t.step_wait(
() => mockPressureService.updatesDelivered() >= (updatesDelivered + 2),
'Wait for more than one update to be delivered to the observer');
mockPressureService.setPressureUpdate('critical', ['power-supply']);
// Deliver more updates, |resolve()| will be called when the new pressure
// state reaches PressureObserver and its callback is invoked
// for the second time.
});
assert_equals(pressureChanges.length, 2);
assert_equals(pressureChanges[0][0].state, 'critical');
assert_equals(pressureChanges[0][0].factors[0], 'thermal');
assert_equals(pressureChanges[1][0].state, 'critical');
assert_equals(pressureChanges[1][0].factors[0], 'power-supply');
}, 'Factors that fail the "has change in data" test are discarded.');
|