aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2015-08-25 21:37:27 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2015-08-25 21:37:27 +0200
commitc5a88e50040fd8f7aa5b8d246fc5f8f1c77836fc (patch)
tree16416424798639dc5470e966c7af60ac8db27522 /activejob/test/cases
parent4788d7fd172e4bac76e1614aa48c58c8d4a09155 (diff)
parent25a4155257cd463355bccb4330b0280e4110de9e (diff)
downloadrails-c5a88e50040fd8f7aa5b8d246fc5f8f1c77836fc.tar.gz
rails-c5a88e50040fd8f7aa5b8d246fc5f8f1c77836fc.tar.bz2
rails-c5a88e50040fd8f7aa5b8d246fc5f8f1c77836fc.zip
Merge pull request #21257 from jdantonio/async-job
Initial implementation of ActiveJob AsyncAdapter.
Diffstat (limited to 'activejob/test/cases')
-rw-r--r--activejob/test/cases/async_job_test.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/activejob/test/cases/async_job_test.rb b/activejob/test/cases/async_job_test.rb
new file mode 100644
index 0000000000..2642cfc608
--- /dev/null
+++ b/activejob/test/cases/async_job_test.rb
@@ -0,0 +1,42 @@
+require 'helper'
+require 'jobs/hello_job'
+require 'jobs/queue_as_job'
+
+class AsyncJobTest < ActiveSupport::TestCase
+ def using_async_adapter?
+ ActiveJob::Base.queue_adapter.is_a? ActiveJob::QueueAdapters::AsyncAdapter
+ end
+
+ setup do
+ ActiveJob::AsyncJob.perform_asynchronously!
+ end
+
+ teardown do
+ ActiveJob::AsyncJob::QUEUES.clear
+ ActiveJob::AsyncJob.perform_immediately!
+ end
+
+ test "#create_thread_pool returns a thread_pool" do
+ thread_pool = ActiveJob::AsyncJob.create_thread_pool
+ assert thread_pool.is_a? Concurrent::ExecutorService
+ assert_not thread_pool.is_a? Concurrent::ImmediateExecutor
+ end
+
+ test "#create_thread_pool returns an ImmediateExecutor after #perform_immediately! is called" do
+ ActiveJob::AsyncJob.perform_immediately!
+ thread_pool = ActiveJob::AsyncJob.create_thread_pool
+ assert thread_pool.is_a? Concurrent::ImmediateExecutor
+ end
+
+ test "enqueuing without specifying a queue uses the default queue" do
+ skip unless using_async_adapter?
+ HelloJob.perform_later
+ assert ActiveJob::AsyncJob::QUEUES.key? 'default'
+ end
+
+ test "enqueuing to a queue that does not exist creates the queue" do
+ skip unless using_async_adapter?
+ QueueAsJob.perform_later
+ assert ActiveJob::AsyncJob::QUEUES.key? QueueAsJob::MY_QUEUE.to_s
+ end
+end