require File.expand_path('test_helper', __dir__) describe 'Backburner::Worker module' do before do Backburner.default_queues.clear clear_jobs!(Backburner.configuration.primary_queue, 'test-plain', 'parent-plain', 'bar.baz.foo') end it 'should support enqueuing plain job' do Backburner::Worker.enqueue TestPlainJob, [7, 9], { ttr: 144 } pop_one_job('test-plain') do |_job, body| assert_equal 'TestPlainJob', body['class'] assert_equal [7, 9], body['args'] assert_equal 144, body['ttr'].to_i end end # plain it 'should support enqueuing parent job' do options = { is_parent: true, limit: 1, timeout: 3, run_on_timeout: true } # Enqueue parent job response = Backburner::Worker.enqueue TestParentJob, [17, 9], options options = { parent_id: response.job_id } # Enqueue child job Backburner::Worker.enqueue TestPlainJob, [7, 9], options pop_one_job('test-plain') do |job, body| assert_equal 'TestPlainJob', body['class'] assert_equal [7, 9], body['args'] job.delete end pop_one_job('parent-plain') do |_job, body| assert_equal [17, 9], body['args'] end end it 'should support enqueuing parent job with timeout' do options = { is_parent: true, limit: 1, timeout: 3, run_on_timeout: true } # Enqueue parent job response = Backburner::Worker.enqueue TestParentJob, [17, 9], options options = { parent_id: response.job_id } # Enqueue child job Backburner::Worker.enqueue TestPlainJob, [7, 9], options pop_one_job('parent-plain') do |_job, body| assert_equal body, nil sleeper(10) end worker = Backburner::Workers::Simple.new('demo.test.parent-plain') worker.prepare TestParentJob.expects(:perform_with_task) job = worker.work_one_job(allq_connection, 'demo.test.parent-plain') assert_equal job.special, "true" end end # options[:parent_id] = opt[:parent_id] if opt[:parent_id] # options[:timeout] = opt[:timeout] if opt[:timeout] # options[:run_on_timeout] = opt[:run_on_timeout] if opt[:run_on_timeout] # options[:limit] = opt[:limit] if opt[:limit] # options[:is_parent] = opt[:is_parent] if opt[:is_parent]