Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testharness.js] Report error for worker errors #11400

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

zcorpan
Copy link
Member

@zcorpan zcorpan commented Jun 7, 2018

In resources/test/tests/functional/worker-dedicated.html remote_done
ends up being called twice, and the second time message_target is
null, which causes an exception to be thrown.

@Ms2ger
Copy link
Contributor

Ms2ger commented Jun 7, 2018

remote_done is called once from the complete message (which is sent because of the "error" event dispatched in the worker) and then another time because another "error" event is dispatched on the Worker. Alternative fix:

--- a/resources/testharness.js
+++ b/resources/testharness.js
@@ -2982,16 +2982,17 @@ policies and contribution forms [3].
                 test.phase = test.phases.HAS_RESULT;
                 test.done();
             } else if (!tests.allow_uncaught_exception) {
                 tests.status.status = tests.status.ERROR;
                 tests.status.message = e.message;
                 tests.status.stack = stack;
             }
             done();
+            e.preventDefault();
         };
 
         addEventListener("error", error_handler, false);
         addEventListener("unhandledrejection", function(e){ error_handler(e.reason); }, false);
     }
 
     test_environment.on_tests_ready();
 

@zcorpan
Copy link
Member Author

zcorpan commented Jun 7, 2018

Thanks, used that instead.

@zcorpan
Copy link
Member Author

zcorpan commented Jun 12, 2018

@Ms2ger ping

@Ms2ger Ms2ger removed their request for review June 12, 2018 15:35
@gsnedders
Copy link
Member

I think that looks good?

Copy link
Member

@gsnedders gsnedders left a comment

Choose a reason for hiding this comment

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

blah

@zcorpan zcorpan force-pushed the zcorpan/remote-done-twice-error branch from 79b96c4 to 47708a5 Compare June 12, 2018 23:46
@wpt-pr-bot
Copy link
Collaborator

There are no owners for this pull request. Please reach out on W3C's irc server (irc.w3.org, port 6665) on channel #testing (web client) to get help with this. Thank you!

@Ms2ger
Copy link
Contributor

Ms2ger commented Jun 13, 2018

This seems like it may be genuine:

::Dedicated Worker Tests <- . FAILED                                     [ 51%]
E     Differing items:
E     {'summarized_status': {'message': None, 'status_string': 'TIMEOUT'}} != {'summarized_status': {'message': 'Error: This failure is expected.', 'status_string': 'ERROR'}}
E     Full diff:
E     - {u'summarized_status': {u'message': None, u'status_string': u'TIMEOUT'},
E     + {u'summarized_status': {u'message': u'Error: This failure is expected.',
E     +                         u'status_string': u'ERROR'},

@zcorpan
Copy link
Member Author

zcorpan commented Jun 13, 2018

I think what happens is that the error worker runs first and sets the harness status to ERROR. Fix for that is #11405

@zcorpan
Copy link
Member Author

zcorpan commented Jun 19, 2018

@jugglinmike see #11400 (comment)

@jugglinmike
Copy link
Contributor

It looks as though the behavior in master and the test are both incorrect.

In master, the script worker-error.js produces a harness state of "ERROR".
I believe thie is a mistake. While it's true that the script produces an
uncaught exception, it does this after loading testharness.js and before
defining other tests. That means testharness.js should consider it a failing
single-page test, and that should not cause a harness error. Complicating
matters is the fact that the script is executed alongside another worker
executing worker.js. That second script is expected to time out.

To summarize: In master, we're seeing an OK (from a single-page test in one
worker) and a TIMEOUT (from a typical test in another worker) incorrectly
reported as an ERROR.

To fix the tests, I've added a sub-test to worker-error.js so that it
actually produces a harness error. I've created another worker script named
worker-uncaught-single.js for use in a new test. The new test verifies that
uncaught errors in workers which are single-page tests do not cause a harness
error.

Although @Ms2ger's recommended solution satisfies both of these tests, I have
also modified the change to testharness.js itself. Rather than preventing
event bubbling from the workers, I'm suggesting that we detach the onerror
event handler immediately following an uncaught error. This approach seems
preferable because it is localized to the situation which motivates it. The
removal of an uneeded event handler is also slightly more hygenic, and it's in
keeping with similar "cleanup" logic that is already present in the
remote_done method.

@zcorpan will be out of office for a few more weeks. @Ms2ger Would you mind
taking another look?

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

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

Do squash the commits before merging, and update the PR title.

@@ -1,3 +1,8 @@
importScripts("/resources/testharness.js");

// The following sub-test ensures that the worker is not interpreted as a
// single-page test. The subsequent uncaught exception should therefor be
Copy link
Contributor

Choose a reason for hiding this comment

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

therefore

Ensure that uncaught exceptions in typical worker tests cause the
harness to report an ERROR status, and update the corresponding test
accordingly. Add a test to verify that the harness reports an OK status
in response to uncaught exceptions which originate from "single-page
test" workers.
@jugglinmike jugglinmike force-pushed the zcorpan/remote-done-twice-error branch from be58932 to f4009c7 Compare July 10, 2018 15:30
@jugglinmike jugglinmike changed the title [testharness.js] Check if this.message_target exists in remote_done [testharness.js] Report error for worker errors Jul 10, 2018
@jugglinmike
Copy link
Contributor

Thanks, @Ms2ger. Typically, I would land this as a series of distinct commits to preserve authorship information. However, because the final changeset does not contain @zcorpan's modification, I've squashed it down into a single commit. And because GitHub.com has been configured to disallow commits pushed from local repositories, I've force-pushed the result to this branch.

For posterity, the pre-squashed version is available here:

zcorpan/remote-done-twice-error...bocoup:zcorpan/remote-done-twice-error

@jugglinmike jugglinmike merged commit 98848df into master Jul 10, 2018
@jugglinmike
Copy link
Contributor

Looks like I forgot to use git's --author flag when squashing, so the commit in master is incorrectly attributed to @zcorpan. Sorry about that, Simon!

@sideshowbarker sideshowbarker deleted the zcorpan/remote-done-twice-error branch November 22, 2018 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants