Bug 1659025 - Fix tests using delay(0) r=smaug
authorKagami Sascha Rosylight <krosylight@mozilla.com>
Thu, 19 May 2022 11:54:31 +0000
changeset 618226 848b3025ef7c540246db27ddc3c287d4266d20cf
parent 618225 6c2ff5402279cb099802ddb42efa8e8135bf7631
child 618227 454e9dcf44198c0d4d43facd7839dd3a411b779e
push id39719
push usersmolnar@mozilla.com
push dateThu, 19 May 2022 16:03:14 +0000
treeherdermozilla-central@cc776278c4ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1659025
milestone102.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1659025 - Fix tests using delay(0) r=smaug There is no guarantee for message events to always preceed `delay(0)`. Differential Revision: https://phabricator.services.mozilla.com/D144605
testing/web-platform/meta/streams/transferable/readable-stream.html.ini
testing/web-platform/meta/streams/transferable/writable-stream.html.ini
testing/web-platform/tests/streams/transferable/readable-stream.html
testing/web-platform/tests/streams/transferable/transform-stream.html
testing/web-platform/tests/streams/transferable/writable-stream.html
deleted file mode 100644
--- a/testing/web-platform/meta/streams/transferable/readable-stream.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[readable-stream.html]
-  [cancel should be propagated to the original]
-    expected: FAIL
deleted file mode 100644
--- a/testing/web-platform/meta/streams/transferable/writable-stream.html.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[writable-stream.html]
-  [abort() should work]
-    expected: FAIL
-
-  [writing a unclonable object should error the stream]
-    expected: FAIL
--- a/testing/web-platform/tests/streams/transferable/readable-stream.html
+++ b/testing/web-platform/tests/streams/transferable/readable-stream.html
@@ -130,37 +130,42 @@ promise_test(async () => {
   assert_false(done, 'we should not be done');
   assert_equals(value.byteLength, 1024, 'expected chunk should be returned');
   // Now the queue contains 0/512 bytes and 1/1 chunk, so pull() is called. If
   // the implementation erroneously counted the extra queue space in bytes, then
   // the queue would contain 1024/513 bytes and pull() wouldn't be called.
   assert_array_equals(rs.events, ['pull'], 'pull() should have been called');
 }, 'the extra queue from transferring is counted in chunks');
 
-promise_test(async () => {
-  const rs = await recordingTransferredReadableStream();
-  rs.cancel('message');
-  await delay(0);
-  assert_array_equals(rs.events, ['pull', 'cancel', 'message'],
-                      'cancel() should have been called');
-  const reader = rs.getReader();
-  // Check the stream really got closed.
-  await reader.closed;
-}, 'cancel should be propagated to the original');
-
-promise_test(async () => {
+async function transferredReadableStreamWithCancelPromise() {
   let resolveCancelCalled;
   const cancelCalled = new Promise(resolve => {
     resolveCancelCalled = resolve;
   });
   const rs = await recordingTransferredReadableStream({
     cancel() {
       resolveCancelCalled();
     }
   });
+  return { rs, cancelCalled };
+}
+
+promise_test(async () => {
+  const { rs, cancelCalled } = await transferredReadableStreamWithCancelPromise();
+  rs.cancel('message');
+  await cancelCalled;
+  assert_array_equals(rs.events, ['pull', 'cancel', 'message'],
+                      'cancel() should have been called');
+  const reader = rs.getReader();
+  // Check the stream really got closed.
+  await reader.closed;
+}, 'cancel should be propagated to the original');
+
+promise_test(async () => {
+  const { rs, cancelCalled } = await transferredReadableStreamWithCancelPromise();
   const reader = rs.getReader();
   const readPromise = reader.read();
   reader.cancel('done');
   const { done } = await readPromise;
   assert_true(done, 'should be done');
   await cancelCalled;
   assert_array_equals(rs.events, ['pull', 'cancel', 'done'],
                       'events should match');
--- a/testing/web-platform/tests/streams/transferable/transform-stream.html
+++ b/testing/web-platform/tests/streams/transferable/transform-stream.html
@@ -61,19 +61,24 @@ test(() => {
 promise_test(t => {
   const source = new ReadableStream({
     start(controller) {
       controller.enqueue('hello ');
       controller.enqueue('there ');
       controller.close();
     }
   });
+  let resolve;
+  const ready = new Promise(r => resolve = r);
   let result = '';
   const sink = new WritableStream({
     write(chunk) {
+      if (result) {
+        resolve();
+      }
       result += chunk;
     }
   });
   const transform1 = new TransformStream({
     transform(chunk, controller) {
       controller.enqueue(chunk.toUpperCase());
     }
   });
@@ -88,17 +93,16 @@ promise_test(t => {
       resolve(data.source
                 .pipeThrough(data.transform1)
                 .pipeThrough(data.transform2)
                 .pipeTo(data.sink));
     }));
   });
   postMessage({source, sink, transform1, transform2}, '*',
               [source, transform1, sink, transform2]);
-  return promise
-    .then(() => delay(0))
+  return ready
     .then(() => {
       assert_equals(result, 'HELLO HELLO THERE THERE ',
                     'transforms should have been applied');
     });
 }, 'piping through transferred transforms should work');
 
 </script>
--- a/testing/web-platform/tests/streams/transferable/writable-stream.html
+++ b/testing/web-platform/tests/streams/transferable/writable-stream.html
@@ -94,43 +94,54 @@ promise_test(async () => {
         resolveWrite = resolve;
       });
     }
   });
   const transferred = await transfer(orig);
   const writer = transferred.getWriter();
   await writer.write('a');
   let writeDone = false;
-  writer.write('b').then(() => {
+  const writePromise = writer.write('b').then(() => {
     writeDone = true;
   });
   await flushAsyncEvents();
   assert_false(writeDone, 'second write should not have resolved yet');
   resolveWrite();
-  await delay(0);
-  assert_true(writeDone, 'second write should have resolved');
+  await writePromise; // (makes sure this doesn't cause timeout)
 }, 'second write should wait for first underlying write to complete');
 
+async function transferredWritableStreamWithAbortPromise() {
+  let resolveAbortCalled;
+  const abortCalled = new Promise(resolve => {
+    resolveAbortCalled = resolve;
+  });
+  const orig = recordingWritableStream({
+    abort() {
+      resolveAbortCalled();
+    }
+  });
+  const transferred = await transfer(orig);
+  return { orig, transferred, abortCalled };
+}
+
 promise_test(async t => {
-  const orig = recordingWritableStream();
-  const transferred = await transfer(orig);
+  const { orig, transferred, abortCalled } = await transferredWritableStreamWithAbortPromise();
   transferred.abort('p');
-  await delay(0);
+  await abortCalled;
   assert_array_equals(orig.events, ['abort', 'p'],
                       'abort() should have been called');
 }, 'abort() should work');
 
 promise_test(async t => {
-  const orig = recordingWritableStream();
-  const transferred = await transfer(orig);
+  const { orig, transferred, abortCalled } = await transferredWritableStreamWithAbortPromise();
   const writer = transferred.getWriter();
   // A WritableStream object cannot be cloned.
   await promise_rejects_dom(t, 'DataCloneError', writer.write(new WritableStream()),
                             'the write should reject');
   await promise_rejects_dom(t, 'DataCloneError', writer.closed,
                             'the stream should be errored');
-  await delay(0);
+  await abortCalled;
   assert_equals(orig.events.length, 2, 'abort should have been called');
   assert_equals(orig.events[0], 'abort', 'first event should be abort');
   assert_equals(orig.events[1].name, 'DataCloneError',
                 'reason should be a DataCloneError');
 }, 'writing a unclonable object should error the stream');
 </script>