aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases/async_job_test.rb
blob: 2642cfc608a037cbbef136468e2dcc350a2135fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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