Skip to content

Commit

Permalink
Add Mike’s terrible appraisal code
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Nov 18, 2016
1 parent 7737da1 commit bdbfbc0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 42 deletions.
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Rake::TestTask.new(:test) do |test|
end

task :default => :test

task :appraise do
exec("cd myapp && rake appraise")
end
1 change: 0 additions & 1 deletion myapp/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
source 'https://rubygems.org'

gem 'appraisal'
gem 'pry'
gem 'sidekiq', :path => '..'
gem 'rails', '5.0.0'
Expand Down
70 changes: 47 additions & 23 deletions myapp/Rakefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
#!/usr/bin/env rake

require File.expand_path('../config/application', __FILE__)
task :appraise do
failed = false

task :test do
require 'timeout'
%w(4 5).each do |ver|
%w(production development).each do |env|
output = `bundle exec ruby integration_setup.rb`
if output.strip != ''
puts output
exit(-1)
end

%(production development).each do |env|
pid = fork do
ENV['RAILS_ENV'] = env
puts eval(File.read("integration_test.rb"))
end
rout, wout = IO.pipe
rerr, werr = IO.pipe

begin
Timeout.timeout(20) do
Process.wait
command = "bundle exec sidekiq"
pid = Process.spawn({'RAILS_ENV' => env, 'BUNDLE_GEMFILE' => "gemfiles/rails_#{ver}.gemfile"},
command, :out => wout, :err => werr)
status = nil
begin
require 'timeout'
Timeout.timeout(10) do
Process.wait(pid)
end
rescue Timeout::Error
Process.kill 9, pid
# collect status so it doesn't stick around as zombie process
Process.wait pid
rescue Timeout::Error
puts "Killing #{pid}"
Process.kill('KILL', pid)
end
status = $?

# close write ends so we could read them
wout.close
werr.close

stdout = rout.readlines
stderr = rerr.readlines

# dispose the read ends of the pipes
rout.close
rerr.close

rc = status.exitstatus
success = stdout.grep(/Success/).size == 3
if success
puts "#{ver}/#{env} success, #{pid}/#{rc}/#{success}"
else
puts stdout.join
puts stderr.join if stderr.size > 0
puts "#{ver}/#{env} failed, #{pid}/#{rc}/#{success}"
failed = true
end
end
puts "#{server} child exited, pid = #{pid}"
Process.wait4(pid)
end
end

if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
task :default => :appraisal
else
task :default => :test
exit(failed ? -1 : 0)
end
1 change: 1 addition & 0 deletions myapp/app/jobs/exit_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ExitJob < ApplicationJob
queue_as :default

def perform(*args)
Sidekiq.logger.warn "Success"
Thread.new do
sleep 0.1
exit(0)
Expand Down
1 change: 1 addition & 0 deletions myapp/app/models/exiter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Exiter
def self.run
Sidekiq.logger.warn "Success"
Thread.new do
sleep 0.1
exit(0)
Expand Down
2 changes: 1 addition & 1 deletion myapp/app/workers/exit_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ExitWorker
include Sidekiq::Worker

def perform
puts Rails.version
logger.warn "Success"
Thread.new do
sleep 0.1
exit(0)
Expand Down
4 changes: 0 additions & 4 deletions myapp/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false

# Configure static file server for tests with Cache-Control for performance.
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Expand Down
14 changes: 1 addition & 13 deletions myapp/integration_test.rb → myapp/integration_setup.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
require 'redis'

# Push three different types of jobs into Redis
r = Redis.new
r.flushdb
r.lpush "queue:default", '{"class":"ExitWorker","args":[],"retry":true,"queue":"default","jid":"4c51e497bbfea959deee0567","created_at":1479409542.279716,"enqueued_at":1479409542.279781}'
r.lpush "queue:default", '{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ExitJob","queue":"default","args":[{"job_class":"ExitJob","job_id":"f8a11fa4-753e-4567-838e-74009ee25cb2","queue_name":"default","priority":null,"arguments":[],"locale":"en"}],"retry":true,"jid":"d020316e37c17bbcd5d360b1","created_at":1479409368.005358,"enqueued_at":1479409368.0056908}'
r.lpush "queue:default", '{"class":"Sidekiq::Extensions::DelayedClass","args":["---\n- !ruby/class \'Exiter\'\n- :run\n- []\n"],"retry":true,"queue":"default","jid":"6006486330d4a27a03593d09","created_at":1479409495.87069,"enqueued_at":1479409495.870754}'

require_relative '../lib/sidekiq/cli'

begin
cli = Sidekiq::CLI.instance
cli.parse
cli.run
rescue => e
raise e if $DEBUG
STDERR.puts e.message
STDERR.puts e.backtrace.join("\n")
exit 1
end

0 comments on commit bdbfbc0

Please sign in to comment.