Bug 1329245 - Part 3: Don't attempt to connect to closed port on OS X, it's flakey. r=bkelly
authorAndrew Sutherland <asutherland@asutherland.org>
Sun, 04 Jun 2017 23:18:16 -0400
changeset 410579 883dfff1524b02f943396cfbb0bb94776423dd6b
parent 410578 81eec5831af85c68447179ee3933e63fe054ef21
child 410580 8d0269a6e46499ab2e15c62d433fa913537096f0
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1329245
milestone55.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 1329245 - Part 3: Don't attempt to connect to closed port on OS X, it's flakey. r=bkelly
dom/network/tests/test_tcpsocket_client_and_server_basics.js
--- a/dom/network/tests/test_tcpsocket_client_and_server_basics.js
+++ b/dom/network/tests/test_tcpsocket_client_and_server_basics.js
@@ -1,10 +1,17 @@
 'use strict';
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+// Bug 788960 and later bug 1329245 have taught us that attempting to connect to
+// a port that is not listening or is no longer listening fails to consistently
+// result in the error (or any) event we expect on Darwin/OSX/"OS X".
+const isOSX = (Services.appinfo.OS === "Darwin");
+const testConnectingToNonListeningPort = !isOSX;
+
 const SERVER_BACKLOG = -1;
 
 const SOCKET_EVENTS = ['open', 'data', 'drain', 'error', 'close'];
 
 function concatUint8Arrays(a, b) {
   let newArr = new Uint8Array(a.length + b.length);
   newArr.set(a, 0);
   newArr.set(b, a.length);
@@ -406,18 +413,21 @@ function* test_basics() {
 
   is(serverReceived.length < (2 * bigUint8Array.length), true, 'Received array length less than sent array length');
 
   // -- Close the listening server (and try to connect)
   // We want to verify that the server actually closes / stops listening when
   // we tell it to.
   listeningServer.close();
 
-  // - try and connect, get an error
-  clientSocket = createSocket('127.0.0.1', serverPort,
-                              { binaryType: 'arraybuffer' });
-  clientQueue = listenForEventsOnSocket(clientSocket, 'client');
-  is((yield clientQueue.waitForEvent()).type, 'error', 'fail to connect');
-  is(clientSocket.readyState, 'closed',
-     'client readyState should be closed after the failure to connect');
+  // (We don't run this check on OS X where it's flakey; see definition up top.)
+  if (testConnectingToNonListeningPort) {
+    // - try and connect, get an error
+    clientSocket = createSocket('127.0.0.1', serverPort,
+                                { binaryType: 'arraybuffer' });
+    clientQueue = listenForEventsOnSocket(clientSocket, 'client');
+    is((yield clientQueue.waitForEvent()).type, 'error', 'fail to connect');
+    is(clientSocket.readyState, 'closed',
+       'client readyState should be closed after the failure to connect');
+  }
 }
 
 add_task(test_basics);