Bug 140043

Summary: js/dom/Promise.html is flaky
Product: WebKit Reporter: Alexey Proskuryakov <ap>
Component: Tools / TestsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ggaren, ryanhaddad, sam
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=160857
Bug Depends on: 147933    
Bug Blocks:    

Description Alexey Proskuryakov 2015-01-02 10:20:28 PST
js/dom/Promise.html is flaky, frequently failing in debug builds. Not sure if it's a test deficiency, or a legitimate bug.

About to run test - promiseAsync
PASS foo is foo
PASS foo is foo
PASS foo is foo
FAIL foo should be bar
Comment 1 Alexey Proskuryakov 2015-01-02 10:32:51 PST
Marked as flaky in <http://trac.webkit.org/r177865>.
Comment 2 Alexey Proskuryakov 2015-01-02 10:36:29 PST
Are promise and setTimeout timers on different event queues?

function promiseAsync() {
  var global = "foo";
  var f = new Promise(function(r1, r2) {
    is(global, "foo", "Global should be foo");
    r1(42);
    is(global, "foo", "Global should still be foo");
    setTimeout(function() {
      is(global, "bar", "Global should still be bar!");
      runTest();
    }, 0);
  }).then(function() {
    global = "bar";
  });
  is(global, "foo", "Global should still be foo (2)");
}
Comment 3 Sam Weinig 2015-01-02 17:34:01 PST
(In reply to comment #2)
> Are promise and setTimeout timers on different event queues?

They are...kind of.
Comment 4 Sam Weinig 2015-01-02 17:39:47 PST
(In reply to comment #3)
> (In reply to comment #2)
> > Are promise and setTimeout timers on different event queues?
> 
> They are...kind of.

I don't think anything in our implementation ensures this ordering, but it really should. This is a great example of why it would be great if we have a unified event loop mechanism.

In this case, the bug is that the .then() should run at the next microtask checkpoint, which is defined as being before the next chance for a timer to fire. Our implementation of Promises does not use the microtask checkpoint, but rather uses ScriptExecutionContext::postTask() mechanism, which is not quite the same thing.