Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Work around for phantom.exit not always exiting correctly on Windows. #2

Merged
merged 1 commit into from

2 participants

@coulsonr

Phil -

I had an issue with phantomjs 1.9.0 not exiting properly in my Windows environment (Windows 7 64-bit). For me, phantomjs.exe will just hang whenever phantom.exit() is called. I've made a change that allows PhantomTestRunner to destroy the phantomjs.exe process based on some known input back from the process stream. It's a bit of a hack, but it is clean in the sense that we know when we want to call phantom.exit(), so we inject a "well known" string that we can take action on that allows us to destroy the process and allow any caller to return. Without this change, my ant task would simply hang indefinitely.

@philmander philmander merged commit a91ad78 into philmander:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 17, 2013
  1. Work around for phantom.exit not always exiting correctly on Windows.…

    Robert Coulson authored
    … Upgrade to phantomjs 1.9.0.
This page is out of date. Refresh to see the latest.
View
10 src/main/java/com/philmander/jstest/PhantomTestRunner.java
@@ -138,8 +138,14 @@ public JsTestResults runTests(String[] testFiles) throws IOException {
StringBuilder message = new StringBuilder();
String line = null;
- while ((line = input.readLine()) != null) {
-
+ boolean keepProcessing = true;
+ while (keepProcessing) {
+ line = input.readLine();
+ if (line != null && line.equalsIgnoreCase("EOF")) {
+ keepProcessing = false;
+ } else {
+ keepProcessing = true;
+ }
//TODO: totally need to refactor reporting parsing
if(logger != null) {
logger.log(line);
View
21 src/main/resources/qunit-phantom-runner.js
@@ -18,7 +18,7 @@ page.onError = function (msg, trace) {
console.log(' ', item.file, ':', item.line);
});
- phantom.exit(1);
+ exit(1);
};
page.onInitialized = function() {
@@ -89,14 +89,14 @@ page.open(url, function(status){
if (status !== "success") {
console.log("Unable to access network: " + status);
- phantom.exit(1);
+ exit(1);
} else {
var interval = setInterval(function() {
if (finished()) {
clearInterval(interval);
- phantom.exit();
+ exit(0);
}
}, 100);
}
@@ -106,4 +106,19 @@ function finished() {
return page.evaluate(function(){
return window.qunitDone;
});
+};
+
+// Hack for phantom.exit not always working.
+//
+// PhantomTestRunner (see line 144) is looking for "EOF" while reading the process output stream
+// and will break the processing loop (and eventually destroy the phantomjs.exe process) if EOF is detected.
+//
+// See
+// https://groups.google.com/forum/?fromgroups#!topic/phantomjs/kaEzJ45VS0c
+//
+// for a lively discussion on phantomjs not always exiting properly in windows.
+function exit(errorCode) {
+ console.log("Exiting with return code: " + errorCode);
+ console.log("EOF");
+ phantom.exit(errorCode);
};
View
BIN  src/test/resources/phantomjs.exe
Binary file not shown
Something went wrong with that request. Please try again.