From 1fd79994e761ff32ebe278e26b3b3f3b0042c248 Mon Sep 17 00:00:00 2001 From: Justin Hart Date: Wed, 16 Oct 2024 10:47:56 -0700 Subject: [PATCH] test our branch --- .github/workflows/ci.yml | 1 + Gemfile | 12 ++- .../resque-scheduler/delayed_job_test.rb | 94 ++++++++++++++++++- 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c585eb..260ea1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: - "4.3.0" - "< 4.9.0" - "~> 4.9" + - "https://github.com/Ibotta/resque-scheduler.git@enqueue-multi-rollback" exclude: # resque-scheduler (= 4.3.0) depends on redis (~> 3.3) - redis-version: "~> 4.8" diff --git a/Gemfile b/Gemfile index 8c785c6..6e6648e 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,8 @@ when /^git:/, /^https:/ when 'latest' gem 'resque' else - gem 'resque', resque_version + versions = resque_version.split(',') + gem 'resque', *versions end case redis_version = ENV.fetch('REDIS_VERSION', 'latest') @@ -19,20 +20,23 @@ when /^git:/, /^https:/ when 'latest' gem 'redis' else - gem 'redis', redis_version + versions = redis_version.split(',') + gem 'redis', *versions end case resque_scheduler_version = ENV.fetch('RESQUE_SCHEDULER_VERSION', 'none') when 'master' gem 'resque-scheduler', git: 'https://github.com/resque/resque-scheduler' when /^git:/, /^https:/ - gem 'resque-scheduler', git: resque_scheduler_version + repo, ref = resque_scheduler_version.split('@', 2) + gem 'resque-scheduler', git: repo, ref: ref when 'latest' gem 'resque-scheduler' when 'none' #noop else - gem 'resque-scheduler', resque_scheduler_version + versions = resque_scheduler_version.split(',') + gem 'resque-scheduler', *versions end gemspec diff --git a/test/integration/resque-scheduler/delayed_job_test.rb b/test/integration/resque-scheduler/delayed_job_test.rb index 363b780..8f6e1ae 100644 --- a/test/integration/resque-scheduler/delayed_job_test.rb +++ b/test/integration/resque-scheduler/delayed_job_test.rb @@ -12,7 +12,6 @@ def setup Resque::Scheduler.quiet = true Resque.redis.redis.flushall @worker = Resque::Worker.new(:test) - # Resque::Scheduler.delayed_requeue_batch_size = 100 end def test_delayed_item_enqueue @@ -30,10 +29,103 @@ def test_delayed_item_enqueue # assert that the active queue has the lonely job if scheduler_version_compare('< 4.9') assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + elsif Resque::Scheduler::VERSION.end_with?('-ibotta') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + else + # this is asserting that > 4.9 "fails" without the patch + assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) + end + end +end + +class LockBatchOffTest < Minitest::Test + + def setup + return unless Resque::Scheduler::VERSION.end_with?('-ibotta') + + @batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches + @batch_size = Resque::Scheduler.delayed_requeue_batch_size + + $success = $lock_failed = $lock_expired = $enqueue_failed = 0 + Resque::Scheduler.quiet = true + Resque.redis.redis.flushall + @worker = Resque::Worker.new(:test) + + Resque::Scheduler.enable_delayed_requeue_batches = false + Resque::Scheduler.delayed_requeue_batch_size = 1 + end + + def teardown + Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled + Resque::Scheduler.delayed_requeue_batch_size = @batch_size + end + + def test_delayed_item_enqueue + t = Time.now + 60 + + # Resque::Scheduler.expects(:enqueue_next_item).never + + # create 90 jobs + 90.times { Resque.enqueue_at(t, LonelyJob) } + assert_equal(90, Resque.delayed_timestamp_size(t)) + + Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) + assert_equal(0, Resque.delayed_timestamp_size(t)) + + # assert that the active queue has the lonely job + if scheduler_version_compare('< 4.9') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + elsif Resque::Scheduler::VERSION.end_with?('-ibotta') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) else # this is asserting that > 4.9 "fails" without the patch assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) end end +end + +class LockBatchOnTest < Minitest::Test + + def setup + return unless Resque::Scheduler::VERSION.end_with?('-ibotta') + + @batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches + @batch_size = Resque::Scheduler.delayed_requeue_batch_size + + $success = $lock_failed = $lock_expired = $enqueue_failed = 0 + Resque::Scheduler.quiet = true + Resque.redis.redis.flushall + @worker = Resque::Worker.new(:test) + + Resque::Scheduler.enable_delayed_requeue_batches = true + Resque::Scheduler.delayed_requeue_batch_size = 100 + end + + def teardown + Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled + Resque::Scheduler.delayed_requeue_batch_size = @batch_size + end + + def test_delayed_item_enqueue + t = Time.now + 60 + # Resque::Scheduler.expects(:enqueue_next_item).never + + # create 90 jobs + 90.times { Resque.enqueue_at(t, LonelyJob) } + assert_equal(90, Resque.delayed_timestamp_size(t)) + + Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) + assert_equal(0, Resque.delayed_timestamp_size(t)) + + # assert that the active queue has the lonely job + if scheduler_version_compare('< 4.9') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + elsif Resque::Scheduler::VERSION.end_with?('-ibotta') + assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) + else + # this is asserting that > 4.9 "fails" without the patch + assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) + end + end end