jenkins-bot has submitted this change and it was merged.

Change subject: Add method to ensure parsoid and mock servers are killed when 
exiting
......................................................................


Add method to ensure parsoid and mock servers are killed when exiting

Based on be83d40bdc0a297049f399276ae2c9a82adf1932 by Arlo.

Change-Id: I9e0de294ec8c86363f0f53da7d53363b8e049b0c
---
M tests/apiServer.js
M tests/client/client.js
M tests/parserTests.js
M tests/roundtrip-test.js
4 files changed, 20 insertions(+), 12 deletions(-)

Approvals:
  Arlolra: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/apiServer.js b/tests/apiServer.js
index edc920a..acdd5e1 100644
--- a/tests/apiServer.js
+++ b/tests/apiServer.js
@@ -20,6 +20,21 @@
 };
 
 /**
+ * Make sure the server is killed if the process exits.
+ */
+var exitOnProcessTerm = function (res) {
+       var stopAndExit = function () {
+               process.exit(res || 0);
+       };
+       process.on('SIGINT', stopAndExit);
+       process.on('SIGTERM', stopAndExit);
+       process.on('uncaughtException', function (e) {
+               console.log(e.stack);
+               stopAndExit();
+       });
+};
+
+/**
  * Starts a server on passed port or a random port if none passed.
  * The callback will get the URL of the started server.
  */
@@ -125,5 +140,6 @@
        startServer: startServer,
        stopServer: stopServer,
        startParsoidServer: startParsoidServer,
-       startMockAPIServer: startMockAPIServer
+       startMockAPIServer: startMockAPIServer,
+       exitOnProcessTerm: exitOnProcessTerm
 };
diff --git a/tests/client/client.js b/tests/client/client.js
index 0e170e3..267fbaa 100755
--- a/tests/client/client.js
+++ b/tests/client/client.js
@@ -238,6 +238,7 @@
                        parsoidURL = url;
                        getGitCommit( getGitCommitCb );
                } );
+               apiServer.exitOnProcessTerm();
        } else {
                getGitCommit( getGitCommitCb );
        }
diff --git a/tests/parserTests.js b/tests/parserTests.js
index 5b47922..f8d8a8e 100755
--- a/tests/parserTests.js
+++ b/tests/parserTests.js
@@ -2113,14 +2113,4 @@
        mockAPIServer = server;
        ptests.main(popts.argv, popts);
 });
-
-function stopTests() {
-       process.exit(0);
-}
-
-process.on('SIGINT', stopTests);
-process.on('SIGTERM', stopTests);
-process.on('uncaughtException', function (e) {
-       console.log(e.stack);
-       stopTests();
-});
+apiServer.exitOnProcessTerm();
diff --git a/tests/roundtrip-test.js b/tests/roundtrip-test.js
index 61ebb81..04d81a0 100755
--- a/tests/roundtrip-test.js
+++ b/tests/roundtrip-test.js
@@ -599,6 +599,7 @@
                                argv.parsoidURL = url;
                                fetch( title, callback, argv );
                        } );
+                       apiServer.exitOnProcessTerm();
                } else {
                        // make sure parsoidURL ends on /
                        if (!/\/$/.test(argv.parsoidURL)) {

-- 
To view, visit https://gerrit.wikimedia.org/r/125390
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9e0de294ec8c86363f0f53da7d53363b8e049b0c
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <marc...@wikimedia.org>
Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: Marcoil <marc...@wikimedia.org>
Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to