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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Check that when addBlocker fails, we store that failure internally
* and include its information in crash report annotation information.
*/
add_task(async function test_addBlockerFailureState() {
info("Testing addBlocker information reported to crash reporter");
let BLOCKER_NAME = "test_addBlocker_state blocker " + Math.random();
// Set up the barrier. Note that we cannot test `barrier.state`
// immediately, as it initially contains "Not started"
let barrier = new AsyncShutdown.Barrier("test_addBlocker_failure");
let deferred = Promise.withResolvers();
barrier.client.addBlocker(BLOCKER_NAME, function () {
return deferred.promise;
});
// Add a blocker and confirm that throws.
const THROWING_BLOCKER_NAME = "test_addBlocker_throws blocker";
Assert.throws(() => {
barrier.client.addBlocker(THROWING_BLOCKER_NAME, Promise.resolve(), 5);
}, /object as third argument/);
let promiseDone = barrier.wait();
// Now that we have called `wait()`, the state should match crash
// reporting info
let crashInfo = barrier._gatherCrashReportTimeoutData(
barrier._name,
barrier.state
);
Assert.deepEqual(
crashInfo.conditions,
barrier.state,
"Barrier state should match crash info."
);
Assert.equal(
crashInfo.brokenAddBlockers.length,
1,
"Should have registered the broken addblocker call."
);
Assert.stringMatches(
crashInfo.brokenAddBlockers?.[0] || "undefined",
THROWING_BLOCKER_NAME,
"Throwing call's blocker name should be listed in message."
);
deferred.resolve();
await promiseDone;
});
|