Permalink
Browse files

explicit quit message

  • Loading branch information...
1 parent b8c0431 commit 1d627dfb23377f33b8cd27d9488cfd137708c0f9 pzel committed Mar 28, 2012
Showing with 18 additions and 7 deletions.
  1. +1 −1 Makefile
  2. +6 −4 spec/shutdown_spec.rb
  3. +11 −2 src/tofu-kozo.js
View
@@ -4,7 +4,7 @@ test:
@bundle exec rspec spec
clean:
- -killall -9 phantomjs
+ -@killall -q -9 phantomjs
@rm -rf /tmp/tofu-kozo
@rm -rf ./phantom.log
@rm -rf ./webserver.log
View
@@ -1,19 +1,21 @@
# coding: utf-8
require './spec/spec_tools.rb'
include SpecTools
-
+
describe "shutdown" do
before :each do
@kozo_port = 10531
@kozo = fork { exec "phantomjs ./src/tofu-kozo.js #{@kozo_port}" }
Process.detach @kozo
sleep 3
end
-
+
it "Can be stopped via HTTP call to /quit" do
- `curl -sS http://localhost:#{@kozo_port}/quit`
+ r = interpret_result `curl -sS http://localhost:#{@kozo_port}/quit`
+ r.should == (ok_msg "Quitting")
sleep 1
pids = `ps aux | grep [p]hantom| awk '{print $2}'`
- pids.split("\n").should_not include @kozo.to_s
+ pids.split("\n").should_not include (@kozo.to_s)
+
end
end
View
@@ -28,6 +28,13 @@ page.getContent = function() {
return res;
};
+page.notBusy = function() {
+ var res = page.evaluate(function(){
+ return document.readyState === "complete";
+ });
+ return res;
+};
+
var makeParams = function(jobToken, obj){
var injection = ("window.TofuParams = {}; window.TofuParams ="+JSON.stringify(obj)+";");
return writeInjection(jobToken, injection);
@@ -54,7 +61,7 @@ var clickElement = function(jobToken, selector) {
var waitForResult = function(jobToken, oldPageBody, ticks) {
if (ticks <= 0) {
return writeResult(jobToken, makeResult("error", "Timed out for "+jobToken));
- } else if (page.getContent() !== oldPageBody) {
+ } else if ((page.getContent() !== oldPageBody) && page.notBusy()) {
return writeResult(jobToken, makeResult("ok", page.getContent()));
} else {
setTimeout(function(){waitForResult(jobToken, oldPageBody, (ticks-1))}, 500);
@@ -125,7 +132,9 @@ var unknownCommand = function(jobToken, url) {
var takeAction = function(jobToken, url) {
if (/^\/quit$/.test(url)) {
- return setTimeout(phantom.exit, 1);
+ phantom.exit();
+ return writeResult(jobToken, makeResult("ok", "Quitting"));
+
} else if (/^\/visit\?url=(.*)/.test(url)) {
var target = decodeURIComponent(url.split("=")[1]);
return visitPage(jobToken, target);

0 comments on commit 1d627df

Please sign in to comment.