diff options
Diffstat (limited to 'activejob/test/support/integration/adapters')
11 files changed, 82 insertions, 113 deletions
diff --git a/activejob/test/support/integration/adapters/async.rb b/activejob/test/support/integration/adapters/async.rb index 42beb12b1f..ba9674d7a1 100644 --- a/activejob/test/support/integration/adapters/async.rb +++ b/activejob/test/support/integration/adapters/async.rb @@ -1,9 +1,12 @@ +# frozen_string_literal: true + module AsyncJobsManager def setup ActiveJob::Base.queue_adapter = :async + ActiveJob::Base.queue_adapter.immediate = false end def clear_jobs - ActiveJob::AsyncJob::QUEUES.clear + ActiveJob::Base.queue_adapter.shutdown end end diff --git a/activejob/test/support/integration/adapters/backburner.rb b/activejob/test/support/integration/adapters/backburner.rb index 2e82562948..1163ae8178 100644 --- a/activejob/test/support/integration/adapters/backburner.rb +++ b/activejob/test/support/integration/adapters/backburner.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module BackburnerJobsManager def setup ActiveJob::Base.queue_adapter = :backburner @@ -6,7 +8,8 @@ module BackburnerJobsManager end unless can_run? puts "Cannot run integration tests for backburner. To be able to run integration tests for backburner you need to install and start beanstalkd.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -23,16 +26,15 @@ module BackburnerJobsManager end def tube - @tube ||= Beaneater::Tube.new(Backburner::Worker.connection, "backburner.worker.queue.integration-tests") # backburner dasherizes the queue name + @tube ||= Beaneater::Tube.new(@worker.connection, "backburner.worker.queue.integration-tests") # backburner dasherizes the queue name end def can_run? begin - Backburner::Worker.connection.send :connect! + @worker = Backburner::Worker.new rescue return false end true end end - diff --git a/activejob/test/support/integration/adapters/delayed_job.rb b/activejob/test/support/integration/adapters/delayed_job.rb index 0b591964bc..fc9bae47fa 100644 --- a/activejob/test/support/integration/adapters/delayed_job.rb +++ b/activejob/test/support/integration/adapters/delayed_job.rb @@ -1,5 +1,7 @@ -require 'delayed_job' -require 'delayed_job_active_record' +# frozen_string_literal: true + +require "delayed_job" +require "delayed_job_active_record" module DelayedJobJobsManager def setup @@ -16,5 +18,6 @@ module DelayedJobJobsManager def stop_workers @worker.stop + @thread.join end end diff --git a/activejob/test/support/integration/adapters/inline.rb b/activejob/test/support/integration/adapters/inline.rb index 83c38f706f..10a97fb941 100644 --- a/activejob/test/support/integration/adapters/inline.rb +++ b/activejob/test/support/integration/adapters/inline.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module InlineJobsManager def setup ActiveJob::Base.queue_adapter = :inline @@ -12,4 +14,3 @@ module InlineJobsManager def stop_workers end end - diff --git a/activejob/test/support/integration/adapters/qu.rb b/activejob/test/support/integration/adapters/qu.rb deleted file mode 100644 index 256ddb3cf3..0000000000 --- a/activejob/test/support/integration/adapters/qu.rb +++ /dev/null @@ -1,38 +0,0 @@ -module QuJobsManager - def setup - require 'qu-rails' - require 'qu-redis' - ActiveJob::Base.queue_adapter = :qu - ENV['REDISTOGO_URL'] = "redis://127.0.0.1:6379/12" - backend = Qu::Backend::Redis.new - backend.namespace = "active_jobs_int_test" - Qu.backend = backend - Qu.logger = Rails.logger - Qu.interval = 0.5 - unless can_run? - puts "Cannot run integration tests for qu. To be able to run integration tests for qu you need to install and start redis.\n" - exit - end - end - - def clear_jobs - Qu.clear "integration_tests" - end - - def start_workers - @thread = Thread.new { Qu::Worker.new("integration_tests").start } - end - - def stop_workers - @thread.kill - end - - def can_run? - begin - Qu.backend.connection.client.connect - rescue - return false - end - true - end -end diff --git a/activejob/test/support/integration/adapters/que.rb b/activejob/test/support/integration/adapters/que.rb index 0cd8952a28..f231e5e12d 100644 --- a/activejob/test/support/integration/adapters/que.rb +++ b/activejob/test/support/integration/adapters/que.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module QueJobsManager def setup - require 'sequel' + require "sequel" ActiveJob::Base.queue_adapter = :que Que.mode = :off Que.worker_count = 1 @@ -11,13 +13,13 @@ module QueJobsManager end def start_workers - que_url = ENV['QUE_DATABASE_URL'] || 'postgres:///active_jobs_que_int_test' + que_url = ENV["QUE_DATABASE_URL"] || "postgres:///active_jobs_que_int_test" uri = URI.parse(que_url) - user = uri.user||ENV['USER'] + user = uri.user || ENV["USER"] pass = uri.password db = uri.path[1..-1] - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database if exists "#{db}"' -U #{user} -t template1} - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'drop database if exists "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'create database "#{db}"' -U #{user} -t template1} Que.connection = Sequel.connect(que_url) Que.migrate! @@ -30,7 +32,8 @@ module QueJobsManager rescue Sequel::DatabaseConnectionError puts "Cannot run integration tests for que. To be able to run integration tests for que you need to install and start postgresql.\n" - exit + status = ENV["CI"] ? false : true + exit status end def stop_workers diff --git a/activejob/test/support/integration/adapters/queue_classic.rb b/activejob/test/support/integration/adapters/queue_classic.rb index 29c04bf625..2b5375461a 100644 --- a/activejob/test/support/integration/adapters/queue_classic.rb +++ b/activejob/test/support/integration/adapters/queue_classic.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module QueueClassicJobsManager def setup - ENV['QC_DATABASE_URL'] ||= 'postgres:///active_jobs_qc_int_test' - ENV['QC_RAILS_DATABASE'] = 'false' - ENV['QC_LISTEN_TIME'] = "0.5" + ENV["QC_DATABASE_URL"] ||= "postgres:///active_jobs_qc_int_test" + ENV["QC_RAILS_DATABASE"] = "false" + ENV["QC_LISTEN_TIME"] = "0.5" ActiveJob::Base.queue_adapter = :queue_classic end @@ -11,27 +13,28 @@ module QueueClassicJobsManager end def start_workers - uri = URI.parse(ENV['QC_DATABASE_URL']) - user = uri.user||ENV['USER'] + uri = URI.parse(ENV["QC_DATABASE_URL"]) + user = uri.user || ENV["USER"] pass = uri.password db = uri.path[1..-1] - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database if exists "#{db}"' -U #{user} -t template1} - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'drop database if exists "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'create database "#{db}"' -U #{user} -t template1} QC::Setup.create QC.default_conn_adapter.disconnect QC.default_conn_adapter = nil @pid = fork do - worker = QC::Worker.new(q_name: 'integration_tests') + worker = QC::Worker.new(q_name: "integration_tests") worker.start end rescue PG::ConnectionBad puts "Cannot run integration tests for queue_classic. To be able to run integration tests for queue_classic you need to install and start postgresql.\n" - exit + status = ENV["CI"] ? false : true + exit status end def stop_workers - Process.kill 'HUP', @pid + Process.kill "HUP", @pid end end diff --git a/activejob/test/support/integration/adapters/resque.rb b/activejob/test/support/integration/adapters/resque.rb index 912f4bc387..2ed8302277 100644 --- a/activejob/test/support/integration/adapters/resque.rb +++ b/activejob/test/support/integration/adapters/resque.rb @@ -1,11 +1,14 @@ +# frozen_string_literal: true + module ResqueJobsManager def setup ActiveJob::Base.queue_adapter = :resque - Resque.redis = Redis::Namespace.new 'active_jobs_int_test', redis: Redis.connect(url: "redis://127.0.0.1:6379/12", :thread_safe => true) + Resque.redis = Redis::Namespace.new "active_jobs_int_test", redis: Redis.new(url: "redis://127.0.0.1:6379/12", thread_safe: true) Resque.logger = Rails.logger unless can_run? puts "Cannot run integration tests for resque. To be able to run integration tests for resque you need to install and start redis.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -39,11 +42,8 @@ module ResqueJobsManager end def can_run? - begin - Resque.redis.client.connect - rescue - return false - end - true + Resque.redis.ping == "PONG" + rescue + false end end diff --git a/activejob/test/support/integration/adapters/sidekiq.rb b/activejob/test/support/integration/adapters/sidekiq.rb index 9aa07bcb52..c79de12eaf 100644 --- a/activejob/test/support/integration/adapters/sidekiq.rb +++ b/activejob/test/support/integration/adapters/sidekiq.rb @@ -1,15 +1,17 @@ -require 'sidekiq/api' +# frozen_string_literal: true -require 'sidekiq/testing' +require "sidekiq/api" + +require "sidekiq/testing" Sidekiq::Testing.disable! module SidekiqJobsManager - def setup ActiveJob::Base.queue_adapter = :sidekiq unless can_run? puts "Cannot run integration tests for sidekiq. To be able to run integration tests for sidekiq you need to install and start redis.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -26,10 +28,10 @@ module SidekiqJobsManager continue_read.close death_write.close - # Celluloid & Sidekiq are not warning-clean :( + # Sidekiq is not warning-clean :( $VERBOSE = false - $stdin.reopen('/dev/null') + $stdin.reopen(File::NULL) $stdout.sync = true $stderr.sync = true @@ -49,14 +51,12 @@ module SidekiqJobsManager self_write.puts("TERM") end - require 'celluloid' - Celluloid.logger = nil - require 'sidekiq/launcher' - sidekiq = Sidekiq::Launcher.new({queues: ["integration_tests"], + require "sidekiq/cli" + require "sidekiq/launcher" + sidekiq = Sidekiq::Launcher.new(queues: ["integration_tests"], environment: "test", concurrency: 1, - timeout: 1, - }) + timeout: 1) Sidekiq.average_scheduled_poll_interval = 0.5 Sidekiq.options[:poll_interval_average] = 1 begin @@ -81,7 +81,7 @@ module SidekiqJobsManager def stop_workers if @pid - Process.kill 'TERM', @pid + Process.kill "TERM", @pid Process.wait @pid end end diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb index 875803a2d8..eb8d4cc2d5 100644 --- a/activejob/test/support/integration/adapters/sneakers.rb +++ b/activejob/test/support/integration/adapters/sneakers.rb @@ -1,34 +1,25 @@ -require 'sneakers/runner' -require 'sneakers/publisher' -require 'timeout' - -module Sneakers - class Publisher - def safe_ensure_connected - @mutex.synchronize do - ensure_connection! unless connected? - end - end - end -end +# frozen_string_literal: true +require "sneakers/runner" +require "timeout" module SneakersJobsManager def setup ActiveJob::Base.queue_adapter = :sneakers - Sneakers.configure :heartbeat => 2, - :amqp => 'amqp://guest:guest@localhost:5672', - :vhost => '/', - :exchange => 'active_jobs_sneakers_int_test', - :exchange_type => :direct, - :daemonize => true, - :threads => 1, - :workers => 1, - :pid_path => Rails.root.join("tmp/sneakers.pid").to_s, - :log => Rails.root.join("log/sneakers.log").to_s + Sneakers.configure heartbeat: 2, + amqp: "amqp://guest:guest@localhost:5672", + vhost: "/", + exchange: "active_jobs_sneakers_int_test", + exchange_type: :direct, + daemonize: true, + threads: 1, + workers: 1, + pid_path: Rails.root.join("tmp/sneakers.pid").to_s, + log: Rails.root.join("log/sneakers.log").to_s unless can_run? puts "Cannot run integration tests for sneakers. To be able to run integration tests for sneakers you need to install and start rabbitmq.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -40,7 +31,7 @@ module SneakersJobsManager @pid = fork do queues = %w(integration_tests) workers = queues.map do |q| - worker_klass = "ActiveJobWorker"+Digest::MD5.hexdigest(q) + worker_klass = "ActiveJobWorker" + Digest::MD5.hexdigest(q) Sneakers.const_set(worker_klass, Class.new(ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper) do from_queue q end) @@ -60,8 +51,8 @@ module SneakersJobsManager end def stop_workers - Process.kill 'TERM', @pid - Process.kill 'TERM', File.open(Rails.root.join("tmp/sneakers.pid").to_s).read.to_i + Process.kill "TERM", @pid + Process.kill "TERM", File.open(Rails.root.join("tmp/sneakers.pid").to_s).read.to_i rescue end @@ -74,11 +65,11 @@ module SneakersJobsManager true end - protected + private def bunny_publisher @bunny_publisher ||= begin p = ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper.send(:publisher) - p.safe_ensure_connected + p.ensure_connection! p end end @@ -86,5 +77,4 @@ module SneakersJobsManager def bunny_queue @queue ||= bunny_publisher.exchange.channel.queue "integration_tests", durable: true end - end diff --git a/activejob/test/support/integration/adapters/sucker_punch.rb b/activejob/test/support/integration/adapters/sucker_punch.rb index 9c0d66b469..099d412c8f 100644 --- a/activejob/test/support/integration/adapters/sucker_punch.rb +++ b/activejob/test/support/integration/adapters/sucker_punch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SuckerPunchJobsManager def setup ActiveJob::Base.queue_adapter = :sucker_punch |