1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/test/support/integration/adapters/que.rb
Matthew Draper d7a058f785 Make AJ integration tests much less verbose
In passing, avoid a blind retry in QC: instead, just fix the problem.
2014-09-27 21:59:10 +09:30

37 lines
1 KiB
Ruby

module QueJobsManager
def setup
require 'sequel'
ActiveJob::Base.queue_adapter = :que
que_url = ENV['QUE_DATABASE_URL'] || 'postgres:///active_jobs_que_int_test'
uri = URI.parse(que_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}
Que.connection = Sequel.connect(que_url)
Que.migrate!
Que.mode = :off
Que.worker_count = 1
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
end
def clear_jobs
Que.clear!
end
def start_workers
@thread = Thread.new do
loop do
Que::Job.work("integration_tests")
sleep 0.5
end
end
end
def stop_workers
@thread.kill
end
end