Bug 1500594 - Retry reading stream if it returns NS_BASE_STREAM_WOULD_BLOCK. r=kershaw, a=test-only
authorValentin Gosu <valentin.gosu@gmail.com>
Fri, 26 Oct 2018 12:28:56 +0000
changeset 498183 7e5a43957be53451b2d48e536f3e8d0b95bd6d8f
parent 498182 67afcd6169b82d3d3c1bfa7524034519c997b1a7
child 498184 fa02a3cb47228ee873efc02896707b77a5bdf7d8
push id10058
push userryanvm@gmail.com
push dateMon, 29 Oct 2018 13:32:17 +0000
treeherdermozilla-beta@52d060761f0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskershaw, test-only
bugs1500594
milestone64.0
Bug 1500594 - Retry reading stream if it returns NS_BASE_STREAM_WOULD_BLOCK. r=kershaw, a=test-only Sometimes nsIBinaryInputStream.readByteArray could return NS_BASE_STREAM_WOULD_BLOCK. In this case we want to retry reading from the input stream. Differential Revision: https://phabricator.services.mozilla.com/D9900
netwerk/test/unit/test_alt-data_simple.js
--- a/netwerk/test/unit/test_alt-data_simple.js
+++ b/netwerk/test/unit/test_alt-data_simple.js
@@ -149,27 +149,35 @@ function readAltContent(request, buffer)
 
   Assert.equal(servedNotModified, true);
   Assert.equal(cc.alternativeDataType, altContentType);
   Assert.equal(buffer, altContent);
   check_has_alt_data_in_index(true);
 
   cc.getOriginalInputStream({
     onInputStreamReady: function(aInputStream) {
-      executeSoon(function() {
-        // We expect the async stream length to match the expected content.
-        // If the test times out, it's probably because of this.
-        let originalData = read_stream(aInputStream, responseContent.length);
-        Assert.equal(originalData, responseContent);
-        requestAgain();
-      });
+      executeSoon(() => readOriginalInputStream(aInputStream));
     }
   });
 }
 
+function readOriginalInputStream(aInputStream)
+{
+  // We expect the async stream length to match the expected content.
+  // If the test times out, it's probably because of this.
+  try {
+    let originalData = read_stream(aInputStream, responseContent.length);
+    Assert.equal(originalData, responseContent);
+    requestAgain();
+  } catch (e) {
+    equal(e.result, Cr.NS_BASE_STREAM_WOULD_BLOCK);
+    executeSoon(() => readOriginalInputStream(aInputStream));
+  }
+}
+
 function requestAgain()
 {
   shouldPassRevalidation = false;
   var chan = make_channel(URL);
   var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
   cc.preferAlternativeDataType(altContentType, "");
   chan.asyncOpen2(new ChannelListener(readEmptyAltContent, null));
 }