Skip to content

Commit 3f592ea

Browse files
committed
test(runtime): cancel a timed-out spec's polls with a per-spec token
The shared specEnded flag was reset by the next spec's beforeEach, so a poll left pending by a spec Jasmine timed out could resume and run assertions or call its old done() during the next spec. Each spec now captures its own token, which afterEach cancels; the terminated-worker poll checks it too.
1 parent a6162c8 commit 3f592ea

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎test-app/app/src/main/assets/app/tests/testRuntimeBoundDispatch.js‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ describe("Runtime-bound Java->JS dispatch", function () {
2121
// Set by a spec whose comparer threads and polls must not outlive it, even
2222
// when jasmine times it out.
2323
var comparingWorker = null;
24-
var specEnded = false;
24+
// One per spec: a callback checks the token its spec captured, so a poll left
25+
// pending by a timed-out spec stays cancelled once the next spec starts.
26+
var currentSpec = null;
2527
beforeEach(function () {
2628
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
2729
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
28-
specEnded = false;
30+
currentSpec = { ended: false };
2931
});
3032
afterEach(function () {
31-
specEnded = true;
33+
currentSpec.ended = true;
3234
if (comparingWorker !== null) {
3335
comparingWorker.terminate();
3436
comparingWorker = null;
@@ -76,11 +78,15 @@ describe("Runtime-bound Java->JS dispatch", function () {
7678
});
7779

7880
it("drops calls to an object whose worker has terminated", function (done) {
81+
var spec = currentSpec;
7982
startWorker(function (worker) {
8083
worker.terminate();
8184

8285
var deadline = Date.now() + 10000;
8386
(function poll() {
87+
if (spec.ended) {
88+
return;
89+
}
8490
// Until teardown completes a call may still be answered.
8591
var result;
8692
try {
@@ -111,11 +117,12 @@ describe("Runtime-bound Java->JS dispatch", function () {
111117
pending("needs android.enableMultithreadedJavascript");
112118
}
113119

120+
var spec = currentSpec;
114121
// Each wait well inside the spec timeout, so a hang fails with its cause.
115122
function waitFor(condition, what, then) {
116123
var deadline = Date.now() + 5000;
117124
(function poll() {
118-
if (specEnded) {
125+
if (spec.ended) {
119126
return;
120127
}
121128
if (condition()) {
@@ -130,7 +137,7 @@ describe("Runtime-bound Java->JS dispatch", function () {
130137
}
131138

132139
comparingWorker = startWorker(function (worker) {
133-
if (specEnded) {
140+
if (spec.ended) {
134141
return;
135142
}
136143
// A comparer stops once it has had 20 dropped calls in a row: by then the worker

0 commit comments

Comments
 (0)