Bug 1426906 - Fix intermittent leak from test_websocket-server.html. r=jryans, a=test-only
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 30 Jan 2018 07:10:26 -0800
changeset 454617 201a4b8a3db0ec041742c58b7ac075bc597c3849
parent 454616 7a901ba2676d35d2c90f8236200985e5f51ae28b
child 454618 1b4ab9a276ce7bb217c02b83057586e7946860f9
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans, test-only
bugs1426906
milestone59.0
Bug 1426906 - Fix intermittent leak from test_websocket-server.html. r=jryans, a=test-only MozReview-Commit-ID: HlPgPjCnA1q
devtools/server/tests/mochitest/chrome.ini
devtools/server/tests/mochitest/test_websocket-server.html
--- a/devtools/server/tests/mochitest/chrome.ini
+++ b/devtools/server/tests/mochitest/chrome.ini
@@ -102,9 +102,8 @@ support-files =
 [test_styles-svg.html]
 [test_unsafeDereference.html]
 [test_webconsole-node-grip.html]
 [test_webextension-addon-debugging-connect.html]
 skip-if = !e10s # test is designed to work on e10s only
 [test_webextension-addon-debugging-reload.html]
 skip-if = !e10s # test is designed to work on e10s only
 [test_websocket-server.html]
-skip-if = os == 'mac' # bug 1294873 intermittent leaks
--- a/devtools/server/tests/mochitest/test_websocket-server.html
+++ b/devtools/server/tests/mochitest/test_websocket-server.html
@@ -19,21 +19,24 @@ window.onload = function () {
 
   const ServerSocket = CC("@mozilla.org/network/server-socket;1",
     "nsIServerSocket", "init");
 
   add_task(function* () {
     // Create a TCP server on auto-assigned port
     let server = new ServerSocket(-1, true, -1);
     ok(server, `Launched WebSocket server on port ${server.port}`);
+
+    let input, output;
+
     server.asyncListen({
       onSocketAccepted: Task.async(function* (socket, transport) {
         info("Accepted incoming connection");
-        let input = transport.openInputStream(0, 0, 0);
-        let output = transport.openOutputStream(0, 0, 0);
+        input = transport.openInputStream(0, 0, 0);
+        output = transport.openOutputStream(0, 0, 0);
 
         // Perform the WebSocket handshake
         let webSocket = yield WebSocketServer.accept(transport, input, output);
 
         // Echo the received message back to the sender
         webSocket.onmessage = ({ data }) => {
           info("Server received message, echoing back");
           webSocket.send(data);
@@ -72,13 +75,17 @@ window.onload = function () {
       client.onerror = reject;
     });
 
     is(echoedMessage, message, "Echoed message matches");
 
     // Close the connection
     client.close();
     yield closed;
+
+    // Prevent leaking the streams by closing them before test ends
+    input.close();
+    output.close();
   });
 };
 </script>
 </body>
 </html>