|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require "test_helper" |
4 | | -require "open3" |
5 | | - |
6 | | -class IntegrationsTest < ActiveSupport::TestCase |
7 | | - test "will prevent loading two integrations" do |
8 | | - with_env("ITERATION_DISABLE_AUTOCONFIGURE", nil) do |
9 | | - rubby = <<~RUBBY |
10 | | - require 'bundler/setup' |
11 | | - require 'job-iteration' |
12 | | - RUBBY |
13 | | - _stdout, stderr, status = run_ruby(rubby) |
14 | | - |
15 | | - assert_equal false, status.success? |
16 | | - assert_match(/resque integration has already been loaded, but sidekiq is also available/, stderr) |
| 4 | + |
| 5 | +class IntegrationsTest < IterationUnitTest |
| 6 | + class IterationJob < ActiveJob::Base |
| 7 | + include JobIteration::Iteration |
| 8 | + |
| 9 | + def build_enumerator(cursor:) |
| 10 | + enumerator_builder.build_once_enumerator(cursor: cursor) |
17 | 11 | end |
18 | | - end |
19 | 12 |
|
20 | | - test "successfully loads one (resque) integration" do |
21 | | - with_env("ITERATION_DISABLE_AUTOCONFIGURE", nil) do |
22 | | - rubby = <<~RUBBY |
23 | | - require 'bundler/setup' |
24 | | - # Remove sidekiq, only resque will be left |
25 | | - $LOAD_PATH.delete_if { |p| p =~ /sidekiq/ } |
26 | | - require 'job-iteration' |
27 | | - RUBBY |
28 | | - _stdout, _stderr, status = run_ruby(rubby) |
29 | | - |
30 | | - assert_equal true, status.success? |
| 13 | + def each_iteration(*) |
31 | 14 | end |
32 | 15 | end |
33 | 16 |
|
34 | | - private |
| 17 | + class ResqueJob < IterationJob |
| 18 | + self.queue_adapter = :resque |
| 19 | + end |
35 | 20 |
|
36 | | - def run_ruby(body) |
37 | | - stdout, stderr, status = nil |
38 | | - Tempfile.open do |f| |
39 | | - f.write(body) |
40 | | - f.close |
| 21 | + class SidekiqJob < IterationJob |
| 22 | + self.queue_adapter = :sidekiq |
| 23 | + end |
41 | 24 |
|
42 | | - command = "ruby #{f.path}" |
43 | | - stdout, stderr, status = Open3.capture3(command) |
44 | | - end |
45 | | - [stdout, stderr, status] |
| 25 | + test "will load two integrations" do |
| 26 | + resque_job = ResqueJob.new.serialize |
| 27 | + ActiveJob::Base.execute(resque_job) |
| 28 | + |
| 29 | + sidekiq_job = SidekiqJob.new.serialize |
| 30 | + ActiveJob::Base.execute(sidekiq_job) |
46 | 31 | end |
47 | 32 |
|
48 | | - def with_env(variable, value) |
49 | | - original = ENV[variable] |
50 | | - ENV[variable] = value |
51 | | - yield |
52 | | - ensure |
53 | | - ENV[variable] = original |
| 33 | + test "handles unknown Active Job queue adapater names" do |
| 34 | + interruption_adapter = JobIteration::Integrations.lookup(:unknown) |
| 35 | + assert_equal(false, interruption_adapter.call) |
54 | 36 | end |
55 | 37 | end |
0 commit comments