2017-07-10 01:49:52 +08:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 21:40:03 +08:00
|
|
|
|
2016-08-07 01:28:46 +08:00
|
|
|
require "rake/testtask"
|
2014-08-12 17:29:21 +08:00
|
|
|
|
2016-05-10 12:07:09 +08:00
|
|
|
#TODO: add qu back to the list after it support Rails 5.1
|
2017-05-28 20:35:15 +08:00
|
|
|
ACTIVEJOB_ADAPTERS = %w(async inline delayed_job que queue_classic resque sidekiq sneakers sucker_punch backburner test)
|
2016-12-22 09:36:08 +08:00
|
|
|
ACTIVEJOB_ADAPTERS.delete("queue_classic") if defined?(JRUBY_VERSION)
|
2014-08-12 17:17:19 +08:00
|
|
|
|
2014-09-14 16:21:55 +08:00
|
|
|
task default: :test
|
2016-08-07 01:28:46 +08:00
|
|
|
task test: "test:default"
|
2014-08-12 17:17:19 +08:00
|
|
|
|
2016-02-01 02:01:03 +08:00
|
|
|
task :package
|
|
|
|
|
2014-08-12 17:29:21 +08:00
|
|
|
namespace :test do
|
2016-08-07 01:28:46 +08:00
|
|
|
desc "Run all adapter tests"
|
2014-09-14 16:21:55 +08:00
|
|
|
task :default do
|
|
|
|
run_without_aborting ACTIVEJOB_ADAPTERS.map { |a| "test:#{a}" }
|
|
|
|
end
|
|
|
|
|
2016-08-07 01:28:46 +08:00
|
|
|
desc "Run all adapter tests in isolation"
|
2014-08-12 17:29:21 +08:00
|
|
|
task :isolated do
|
2014-09-14 16:21:55 +08:00
|
|
|
run_without_aborting ACTIVEJOB_ADAPTERS.map { |a| "test:isolated:#{a}" }
|
2014-08-12 17:29:21 +08:00
|
|
|
end
|
2014-08-18 15:19:41 +08:00
|
|
|
|
2016-08-07 01:28:46 +08:00
|
|
|
desc "Run integration tests for all adapters"
|
2014-08-18 15:19:41 +08:00
|
|
|
task :integration do
|
2016-08-07 01:28:46 +08:00
|
|
|
run_without_aborting (ACTIVEJOB_ADAPTERS - ["test"]).map { |a| "test:integration:#{a}" }
|
2014-09-14 16:21:55 +08:00
|
|
|
end
|
|
|
|
|
2016-08-07 01:28:46 +08:00
|
|
|
task "env:integration" do
|
|
|
|
ENV["AJ_INTEGRATION_TESTS"] = "1"
|
2014-08-18 15:19:41 +08:00
|
|
|
end
|
2014-08-12 17:29:21 +08:00
|
|
|
|
2014-09-14 16:21:55 +08:00
|
|
|
ACTIVEJOB_ADAPTERS.each do |adapter|
|
2016-08-07 01:28:46 +08:00
|
|
|
task("env:#{adapter}") { ENV["AJ_ADAPTER"] = adapter }
|
2014-08-12 17:29:21 +08:00
|
|
|
|
2014-09-14 16:21:55 +08:00
|
|
|
Rake::TestTask.new(adapter => "test:env:#{adapter}") do |t|
|
|
|
|
t.description = "Run adapter tests for #{adapter}"
|
2016-08-07 01:28:46 +08:00
|
|
|
t.libs << "test"
|
|
|
|
t.test_files = FileList["test/cases/**/*_test.rb"]
|
2014-08-12 17:29:21 +08:00
|
|
|
t.verbose = true
|
2015-05-04 05:01:10 +08:00
|
|
|
t.warning = false
|
2014-09-27 22:37:44 +08:00
|
|
|
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
2014-08-12 17:29:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
namespace :isolated do
|
2014-09-14 16:21:55 +08:00
|
|
|
task adapter => "test:env:#{adapter}" do
|
2017-05-15 22:17:28 +08:00
|
|
|
Dir.glob("#{__dir__}/test/cases/**/*_test.rb").all? do |file|
|
|
|
|
sh(Gem.ruby, "-w", "-I#{__dir__}/lib", "-I#{__dir__}/test", file)
|
2016-09-02 05:41:49 +08:00
|
|
|
end || raise("Failures")
|
2014-08-12 17:29:21 +08:00
|
|
|
end
|
|
|
|
end
|
2014-08-18 15:19:41 +08:00
|
|
|
|
|
|
|
namespace :integration do
|
2016-08-07 01:28:46 +08:00
|
|
|
Rake::TestTask.new(adapter => ["test:env:#{adapter}", "test:env:integration"]) do |t|
|
2014-09-14 16:21:55 +08:00
|
|
|
t.description = "Run integration tests for #{adapter}"
|
2016-08-07 01:28:46 +08:00
|
|
|
t.libs << "test"
|
|
|
|
t.test_files = FileList["test/integration/**/*_test.rb"]
|
2014-08-18 15:19:41 +08:00
|
|
|
t.verbose = true
|
2015-05-04 05:01:10 +08:00
|
|
|
t.warning = false
|
2014-09-27 22:37:44 +08:00
|
|
|
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
2014-08-18 15:19:41 +08:00
|
|
|
end
|
|
|
|
end
|
2014-08-12 17:17:19 +08:00
|
|
|
end
|
2014-09-14 16:21:55 +08:00
|
|
|
end
|
2014-08-12 17:17:19 +08:00
|
|
|
|
2014-09-14 16:21:55 +08:00
|
|
|
def run_without_aborting(tasks)
|
|
|
|
errors = []
|
2014-08-18 15:19:41 +08:00
|
|
|
|
2014-09-14 16:21:55 +08:00
|
|
|
tasks.each do |task|
|
|
|
|
begin
|
|
|
|
Rake::Task[task].invoke
|
|
|
|
rescue Exception
|
|
|
|
errors << task
|
2014-08-18 15:19:41 +08:00
|
|
|
end
|
2014-08-12 17:17:19 +08:00
|
|
|
end
|
|
|
|
|
2014-09-14 16:21:55 +08:00
|
|
|
abort "Errors running #{errors.join(', ')}" if errors.any?
|
2014-08-12 17:17:19 +08:00
|
|
|
end
|