Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Unblock test promise chain when done() is called early. #226

Merged
merged 1 commit into from
Jan 25, 2017

Conversation

pwnall
Copy link
Contributor

@pwnall pwnall commented Dec 13, 2016

This makes it possible to end a promise_test by calling Test.done(). Previously, that would work for a single test, but would get any follow-up test stuck waiting for the global promise chain to resolve.

Test case below. Without the patch, the first test times out and the second test passes. With the patch, both tests pass.

<!doctype html>
<script src="testharness.js"></script>
<script src="testharnessreport.js"></script>
<script>

promise_test(t => new Promise((resolve, reject) => {
  t.done();
}), 'First promise test');

promise_test(() => Promise.resolve(), 'Second promise test');

</script>

Credit: The fix does not belong to me. I implemented the solution proposed in #225 (comment)

Question: should the race promise reject and complain that Test.done() was called in a promise_test before the test's promise resolved?


This change is Reviewable

var promise = test.step(func, test, test);
test.step(function() {
assert_not_equals(promise, undefined);
});
return Promise.resolve(promise)
return Promise.race([promise, earlyDonePromise])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bit weird to call done() again after earlyDonePromise resolves. Possibly cleaner (and just as correct) would be to get rid of the "return" on this line, and add a "return earlyDonePromise" (maybe renamed to just "donePromise") after it? That way it's clear that the next test always is started when done is called, and the block here is just to make sure done is called when the passed in promise resolves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, PTAL?

This makes it possible to end a promise_test by calling Test.done().
Previously, that would work for a single test, but would get any
follow-up test stuck waiting for the global promise chain to resolve.
@Ms2ger
Copy link
Contributor

Ms2ger commented Jan 24, 2017

@mkruisselbrink thoughts?

@mkruisselbrink
Copy link
Contributor

@mkruisselbrink thoughts?

I think this looks good.

Question: should the race promise reject and complain that Test.done() was called in a promise_test before the test's promise resolved?

I don't think it should. Test.step() also doesn't complain if it is called after a test has finished (it just silently doesn't do anything), so I think it's reasonable to similarly quietly ignore if the promise passed to promise_test resolves or rejects after Test.done() is called.

@Ms2ger Ms2ger merged commit 7e0a754 into w3c:master Jan 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants