Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing Conductor Ruby 1.8.7 upgrade to 1.9.3
require 'rubygems'
require 'rest_client'
require 'fileutils'
require 'logger'
require 'childprocess'
require 'yaml'
module Conductor
module Verifier
class Runner
BEFORE_BRANCH = 'ruby-1.8.7'.freeze
AFTER_BRANCH = 'ruby-1.9.3'.freeze
CONDUCTOR_ROOT = "/path/to/my/local/instance".freeze
PORT = 3000
def initialize
cleanup!
end
def run
YAML.load_file(File.expand_path('urls.yml', File.dirname(__FILE__))).each do |site|
synchronize_templates_for(site[:domain])
process_site_branch(site, BEFORE_BRANCH)
process_site_branch(site, AFTER_BRANCH)
sleep(5)
compare(site, BEFORE_BRANCH, AFTER_BRANCH)
end
end
private
def process_site_branch(site, branch)
begin
command = %(cd #{CONDUCTOR_ROOT} && git stash && git co #{branch} && HOST=#{site[:domain]} rails server -p #{PORT})
puts "\n\nStarting: #{command}\n\n"
process = ChildProcess.build(command)
process.start
sleep(60)
site[:paths].each do |path|
retry_count = 0
begin
sleep(2)
url = File.join("http://localhost:#{PORT}", path)
target = target_for(branch, site[:domain], path)
puts "Before request: #{url}"
response = RestClient.get(url, :accept => :html)
FileUtils.mkdir_p(File.dirname(target))
File.open(target, 'w+') do |file|
file.puts response.body
end
puts "After writing response for: #{url}"
rescue RestClient::ResourceNotFound, RestClient::InternalServerError => e
FileUtils.mkdir_p(File.dirname(target))
File.open(target, 'w+') do |file|
file.puts e.response.body
end
rescue RestClient::ServerBrokeConnection, Errno::ECONNREFUSED, RuntimeError => e
retry_count += 1
if retry_count < 3
sleep(3)
retry
else
raise RuntimeError, "site: #{site[:domain]}\tpath: #{path}\tbranch: #{branch}\n#{e}"
end
end
end
ensure
begin
process.poll_for_exit(10)
rescue ChildProcess::TimeoutError
process.stop # tries increasingly harsher methods to kill the process.
end
end
end
def working_directory
File.join(File.dirname(__FILE__), "../tmp", "from-#{BEFORE_BRANCH}-to-#{AFTER_BRANCH}")
end
def working_directory_for(branch, domain)
File.join(working_directory, branch, domain)
end
def target_for(branch, domain, path)
File.join(working_directory_for(branch, domain), "#{path.sub(/\/$/, '')}.html")
end
def cleanup!
`rm -rf #{working_directory}`
FileUtils.mkdir_p(working_directory) rescue true
end
def compare(site, before, after)
@logger = ::Logger.new(File.join(working_directory, 'diff.log'))
@logger.info(site[:domain]) {"BEGIN DIFF #{site[:domain]}"}
@logger.info(site[:domain]) {`diff -urwBN #{File.join(working_directory_for(before, site[:domain]))} #{File.join(working_directory_for(after, site[:domain]))}`}
@logger.info(site[:domain]) {"END DIFF #{site[:domain]}"}
end
end
end
end
Conductor::Verifier::Runner.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.