Permalink
Browse files

Swapping out httpq for Redis

  • Loading branch information...
1 parent f0902bf commit 4ab92d077e68c25e30704378a0b3121fca437d65 @brynary committed Sep 14, 2009
View
@@ -1,10 +0,0 @@
-#!/usr/bin/env ruby
-
-require "rubygems"
-require "rack"
-require "webrick"
-
-require File.expand_path(File.dirname(__FILE__) + "/../lib/testjour")
-require "testjour/http_queue"
-
-Testjour::HttpQueue.run_on(Rack::Handler::WEBrick)
@@ -11,78 +11,75 @@
module Testjour
module Commands
-
+
class Run < Command
-
+
def execute
configuration.unshift_args(testjour_yml_args)
configuration.parse!
-
- HttpQueue.with_queue_server do
- configuration.setup
-
- if configuration.feature_files.any?
- queue_features
-
- @started_slaves = 0
- start_slaves
-
- puts "Requested build from #{@started_slaves} slaves... (Waiting for #{step_counter.count} results)"
- puts
-
- print_results
- else
- Testjour.logger.info("No feature files. Quitting.")
- end
+ configuration.setup
+
+ if configuration.feature_files.any?
+ RedisQueue.reset_all
+ queue_features
+
+ @started_slaves = 0
+ start_slaves
+
+ puts "Requested build from #{@started_slaves} slaves... (Waiting for #{step_counter.count} results)"
+ puts
+
+ print_results
+ else
+ Testjour.logger.info("No feature files. Quitting.")
end
end
-
+
def queue_features
Testjour.logger.info("Queuing features...")
-
- HttpQueue.with_queue(queue_uri) do |queue|
- configuration.feature_files.each do |feature_file|
- queue.push(:feature_files, feature_file)
- Testjour.logger.info "Queued: #{feature_file}"
- end
+ queue = RedisQueue.new
+
+ configuration.feature_files.each do |feature_file|
+ queue.push(:feature_files, feature_file)
+ Testjour.logger.info "Queued: #{feature_file}"
end
end
-
+
def start_slaves
start_local_slaves
start_remote_slaves
end
-
+
def start_local_slaves
configuration.local_slave_count.times do
@started_slaves += 1
start_slave
end
end
-
+
def start_remote_slaves
configuration.remote_slaves.each do |remote_slave|
@started_slaves += 1
start_remote_slave(remote_slave)
end
end
-
+
def start_remote_slave(remote_slave)
uri = URI.parse(remote_slave)
cmd = remote_slave_run_command(uri.host, uri.path)
Testjour.logger.info "Starting remote slave: #{cmd}"
detached_exec(cmd)
end
-
+
def remote_slave_run_command(host, path)
"ssh #{host} testjour run:remote --in=#{path} #{configuration.run_slave_args.join(' ')} #{testjour_uri}".squeeze(" ")
end
-
+
def start_slave
Testjour.logger.info "Starting slave: #{local_run_command}"
detached_exec(local_run_command)
end
-
+
def testjour_yml_args
@testjour_yml_args ||= begin
if File.exist?("testjour.yml")
@@ -92,62 +89,52 @@ def testjour_yml_args
end
end
end
-
+
def print_results
results_formatter = ResultsFormatter.new(step_counter, configuration.options)
-
- HttpQueue.with_queue(queue_uri) do |queue|
- step_counter.count.times do
- results_formatter.result(queue.pop(:results))
+ queue = RedisQueue.new
+ results_count = 0
+
+ Timeout.timeout(180) do
+ while results_count < step_counter.count
+ if (result = queue.pop(:results))
+ results_formatter.result(result)
+ results_count += 1
+ else
+ sleep 0.1
+ end
end
end
-
+
results_formatter.finish
-
return results_formatter.failed? ? 1 : 0
- rescue => ex
- if ex.message =~ /result overdue/
- $stderr.puts
- $stderr.puts "Missing steps:"
- $stderr.puts
- results_formatter.missing_backtrace_lines.each do |line|
- $stderr.puts " #{line}"
- end
- $stderr.puts
- end
-
- raise
end
-
+
def step_counter
return @step_counter if @step_counter
-
+
features = load_plain_text_features(configuration.feature_files)
@step_counter = Testjour::StepCounter.new(step_mother)
@step_counter.options = configuration.cucumber_configuration.options
@step_counter.visit_features(features)
return @step_counter
end
-
+
def local_run_command
"testjour run:slave #{configuration.run_slave_args.join(' ')} #{testjour_uri}".squeeze(" ")
end
-
- def queue_uri
- "http://localhost:#{Testjour::HttpQueue.port}/"
- end
-
+
def testjour_uri
user = `whoami`.strip
host = Socket.gethostname
- "http://#{user}@#{host}:#{Testjour::HttpQueue.port}" + File.expand_path(".")
+ "http://#{user}@#{host}" + File.expand_path(".")
end
-
+
def testjour_path
File.expand_path(File.dirname(__FILE__) + "/../../../bin/testjour")
end
-
+
end
-
+
end
end
@@ -31,31 +31,30 @@ def execute
end
def work
- HttpQueue.with_queue(configuration.queue_uri) do |queue|
- feature_file = true
+ queue = RedisQueue.new
+ feature_file = true
- while feature_file
- begin
- feature_file = queue.pop(:feature_files)
- rescue Curl::Err::ConnectionFailedError
- feature_file = false
- end
+ while feature_file
+ begin
+ feature_file = queue.pop(:feature_files)
+ rescue Curl::Err::ConnectionFailedError
+ feature_file = false
+ end
- if feature_file
- Testjour.logger.info "Running: #{feature_file}"
- features = load_plain_text_features(feature_file)
- Testjour.logger.info "Loaded: #{feature_file}"
- execute_features(features)
- Testjour.logger.info "Finished running: #{feature_file}"
- else
- Testjour.logger.info "No feature file found. Finished"
- end
+ if feature_file
+ Testjour.logger.info "Running: #{feature_file}"
+ features = load_plain_text_features(feature_file)
+ Testjour.logger.info "Loaded: #{feature_file}"
+ execute_features(features)
+ Testjour.logger.info "Finished running: #{feature_file}"
+ else
+ Testjour.logger.info "No feature file found. Finished"
end
end
end
def execute_features(features)
- visitor = Testjour::HttpFormatter.new(step_mother, StringIO.new, configuration.queue_uri)
+ visitor = Testjour::HttpFormatter.new(step_mother)
visitor.options = configuration.cucumber_configuration.options
Testjour.logger.info "Visiting..."
visitor.visit_features(features)
@@ -7,11 +7,6 @@ module Testjour
class HttpFormatter < ::Cucumber::Ast::Visitor
- def initialize(step_mother, io, queue_uri)
- super(step_mother)
- @queue_uri = queue_uri
- end
-
def visit_multiline_arg(multiline_arg)
@multiline_arg = true
super
@@ -36,9 +31,8 @@ def visit_table_cell_value(value, status)
private
def progress(time, step_invocation, status = nil)
- HttpQueue.with_queue(@queue_uri) do |queue|
- queue.push(:results, Result.new(time, step_invocation, status))
- end
+ queue = RedisQueue.new
+ queue.push(:results, Result.new(time, step_invocation, status))
end
end
Oops, something went wrong.

0 comments on commit 4ab92d0

Please sign in to comment.