From 7737da1744c5c8382ed0926f87423b7cbb6c53ec Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Thu, 17 Nov 2016 14:40:09 -0800 Subject: [PATCH] initial work on appraisal and rails integration testing, #3241 --- myapp/Appraisals | 7 ++ myapp/Gemfile | 1 + myapp/Rakefile | 32 +++++-- myapp/app/jobs/application_job.rb | 2 + myapp/app/jobs/exit_job.rb | 10 ++ myapp/app/models/exiter.rb | 8 ++ myapp/app/workers/exit_worker.rb | 11 +++ myapp/gemfiles/rails_4.gemfile | 13 +++ myapp/gemfiles/rails_4.gemfile.lock | 137 +++++++++++++++++++++++++++ myapp/gemfiles/rails_5.gemfile | 13 +++ myapp/gemfiles/rails_5.gemfile.lock | 141 ++++++++++++++++++++++++++++ myapp/integration_test.rb | 20 ++++ 12 files changed, 387 insertions(+), 8 deletions(-) create mode 100644 myapp/Appraisals create mode 100644 myapp/app/jobs/application_job.rb create mode 100644 myapp/app/jobs/exit_job.rb create mode 100644 myapp/app/models/exiter.rb create mode 100644 myapp/app/workers/exit_worker.rb create mode 100644 myapp/gemfiles/rails_4.gemfile create mode 100644 myapp/gemfiles/rails_4.gemfile.lock create mode 100644 myapp/gemfiles/rails_5.gemfile create mode 100644 myapp/gemfiles/rails_5.gemfile.lock create mode 100644 myapp/integration_test.rb diff --git a/myapp/Appraisals b/myapp/Appraisals new file mode 100644 index 00000000..13c017e4 --- /dev/null +++ b/myapp/Appraisals @@ -0,0 +1,7 @@ +appraise "rails-4" do + gem "rails", "4.2.7" +end + +appraise "rails-5" do + gem "rails", "5.0.0" +end diff --git a/myapp/Gemfile b/myapp/Gemfile index 495a0c87..3c3d5c89 100644 --- a/myapp/Gemfile +++ b/myapp/Gemfile @@ -1,5 +1,6 @@ source 'https://rubygems.org' +gem 'appraisal' gem 'pry' gem 'sidekiq', :path => '..' gem 'rails', '5.0.0' diff --git a/myapp/Rakefile b/myapp/Rakefile index 8814e3d6..ffca9f08 100644 --- a/myapp/Rakefile +++ b/myapp/Rakefile @@ -1,16 +1,32 @@ #!/usr/bin/env rake -# Add your own tasks in files placed in lib/tasks ending in .rake, -# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) -Myapp::Application.load_tasks +task :test do + require 'timeout' -task :load_jobs => :environment do - require 'sidekiq/api' - Sidekiq::Queue.new.clear + %(production development).each do |env| + pid = fork do + ENV['RAILS_ENV'] = env + puts eval(File.read("integration_test.rb")) + end - 50_000.times do |x| - EmptyWorker.perform_async + begin + Timeout.timeout(20) do + Process.wait + end + rescue Timeout::Error + Process.kill 9, pid + # collect status so it doesn't stick around as zombie process + Process.wait pid + 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 +end diff --git a/myapp/app/jobs/application_job.rb b/myapp/app/jobs/application_job.rb new file mode 100644 index 00000000..a009ace5 --- /dev/null +++ b/myapp/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/myapp/app/jobs/exit_job.rb b/myapp/app/jobs/exit_job.rb new file mode 100644 index 00000000..284b6343 --- /dev/null +++ b/myapp/app/jobs/exit_job.rb @@ -0,0 +1,10 @@ +class ExitJob < ApplicationJob + queue_as :default + + def perform(*args) + Thread.new do + sleep 0.1 + exit(0) + end + end +end diff --git a/myapp/app/models/exiter.rb b/myapp/app/models/exiter.rb new file mode 100644 index 00000000..0ea8ca34 --- /dev/null +++ b/myapp/app/models/exiter.rb @@ -0,0 +1,8 @@ +class Exiter + def self.run + Thread.new do + sleep 0.1 + exit(0) + end + end +end diff --git a/myapp/app/workers/exit_worker.rb b/myapp/app/workers/exit_worker.rb new file mode 100644 index 00000000..bd1eab86 --- /dev/null +++ b/myapp/app/workers/exit_worker.rb @@ -0,0 +1,11 @@ +class ExitWorker + include Sidekiq::Worker + + def perform + puts Rails.version + Thread.new do + sleep 0.1 + exit(0) + end + end +end diff --git a/myapp/gemfiles/rails_4.gemfile b/myapp/gemfiles/rails_4.gemfile new file mode 100644 index 00000000..81475001 --- /dev/null +++ b/myapp/gemfiles/rails_4.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "pry" +gem "sidekiq", :path => "../.." +gem "rails", "4.2.7" + +platforms :ruby do + gem "sqlite3" + gem "redis-namespace" +end diff --git a/myapp/gemfiles/rails_4.gemfile.lock b/myapp/gemfiles/rails_4.gemfile.lock new file mode 100644 index 00000000..babe9c58 --- /dev/null +++ b/myapp/gemfiles/rails_4.gemfile.lock @@ -0,0 +1,137 @@ +PATH + remote: ../.. + specs: + sidekiq (4.2.6) + concurrent-ruby (~> 1.0) + connection_pool (~> 2.2, >= 2.2.0) + rack-protection (>= 1.5.0) + redis (~> 3.2, >= 3.2.1) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.7) + actionpack (= 4.2.7) + actionview (= 4.2.7) + activejob (= 4.2.7) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.7) + actionview (= 4.2.7) + activesupport (= 4.2.7) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.7) + activesupport (= 4.2.7) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.7) + activesupport (= 4.2.7) + globalid (>= 0.3.0) + activemodel (4.2.7) + activesupport (= 4.2.7) + builder (~> 3.1) + activerecord (4.2.7) + activemodel (= 4.2.7) + activesupport (= 4.2.7) + arel (~> 6.0) + activesupport (4.2.7) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + appraisal (2.1.0) + bundler + rake + thor (>= 0.14.0) + arel (6.0.3) + builder (3.2.2) + coderay (1.1.1) + concurrent-ruby (1.0.2) + connection_pool (2.2.0) + erubis (2.7.0) + globalid (0.3.7) + activesupport (>= 4.1.0) + i18n (0.7.0) + json (1.8.3) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.1) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rack (1.6.4) + rack-protection (1.5.3) + rack + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.7) + actionmailer (= 4.2.7) + actionpack (= 4.2.7) + actionview (= 4.2.7) + activejob (= 4.2.7) + activemodel (= 4.2.7) + activerecord (= 4.2.7) + activesupport (= 4.2.7) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.7) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.7) + actionpack (= 4.2.7) + activesupport (= 4.2.7) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (11.3.0) + redis (3.3.1) + redis-namespace (1.5.2) + redis (~> 3.0, >= 3.0.4) + slop (3.6.0) + sprockets (3.7.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.11) + thor (0.19.1) + thread_safe (0.3.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + pry + rails (= 4.2.7) + redis-namespace + sidekiq! + sqlite3 + +BUNDLED WITH + 1.12.5 diff --git a/myapp/gemfiles/rails_5.gemfile b/myapp/gemfiles/rails_5.gemfile new file mode 100644 index 00000000..6d0d97ff --- /dev/null +++ b/myapp/gemfiles/rails_5.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "pry" +gem "sidekiq", :path => "../.." +gem "rails", "5.0.0" + +platforms :ruby do + gem "sqlite3" + gem "redis-namespace" +end diff --git a/myapp/gemfiles/rails_5.gemfile.lock b/myapp/gemfiles/rails_5.gemfile.lock new file mode 100644 index 00000000..0ab56222 --- /dev/null +++ b/myapp/gemfiles/rails_5.gemfile.lock @@ -0,0 +1,141 @@ +PATH + remote: ../.. + specs: + sidekiq (4.2.6) + concurrent-ruby (~> 1.0) + connection_pool (~> 2.2, >= 2.2.0) + rack-protection (>= 1.5.0) + redis (~> 3.2, >= 3.2.1) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.0.0) + actionpack (= 5.0.0) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.0) + actionpack (= 5.0.0) + actionview (= 5.0.0) + activejob (= 5.0.0) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.0) + actionview (= 5.0.0) + activesupport (= 5.0.0) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.0) + activesupport (= 5.0.0) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (5.0.0) + activesupport (= 5.0.0) + globalid (>= 0.3.6) + activemodel (5.0.0) + activesupport (= 5.0.0) + activerecord (5.0.0) + activemodel (= 5.0.0) + activesupport (= 5.0.0) + arel (~> 7.0) + activesupport (5.0.0) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + appraisal (2.1.0) + bundler + rake + thor (>= 0.14.0) + arel (7.1.4) + builder (3.2.2) + coderay (1.1.1) + concurrent-ruby (1.0.2) + connection_pool (2.2.0) + erubis (2.7.0) + globalid (0.3.7) + activesupport (>= 4.1.0) + i18n (0.7.0) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.1) + nio4r (1.2.1) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rack (2.0.1) + rack-protection (1.5.3) + rack + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.0) + actioncable (= 5.0.0) + actionmailer (= 5.0.0) + actionpack (= 5.0.0) + actionview (= 5.0.0) + activejob (= 5.0.0) + activemodel (= 5.0.0) + activerecord (= 5.0.0) + activesupport (= 5.0.0) + bundler (>= 1.3.0, < 2.0) + railties (= 5.0.0) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.1) + activesupport (>= 4.2.0, < 6.0) + nokogiri (~> 1.6.0) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.0.0) + actionpack (= 5.0.0) + activesupport (= 5.0.0) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (11.3.0) + redis (3.3.1) + redis-namespace (1.5.2) + redis (~> 3.0, >= 3.0.4) + slop (3.6.0) + sprockets (3.7.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.11) + thor (0.19.1) + thread_safe (0.3.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + websocket-driver (0.6.4) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + pry + rails (= 5.0.0) + redis-namespace + sidekiq! + sqlite3 + +BUNDLED WITH + 1.12.5 diff --git a/myapp/integration_test.rb b/myapp/integration_test.rb new file mode 100644 index 00000000..8d040ca3 --- /dev/null +++ b/myapp/integration_test.rb @@ -0,0 +1,20 @@ +require '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