Sha256: b63da9c01bc77a28c55617e2f91447b78615b299dd4f98b0126c6031f2818516
Contents?: true
Size: 1.33 KB
Versions: 3
Compression:
Stored size: 1.33 KB
Contents
require 'spec_helper' require 'sidekiq/api' require 'sidekiq/debounce/middleware' class DebouncedWorker include Sidekiq::Worker sidekiq_options debounce: true def perform(_a, _b); end end describe Sidekiq::Debounce do before do stub_scheduled_set end after do Sidekiq.redis(&:flushdb) end let(:set) { Sidekiq::ScheduledSet.new } let(:sorted_entry) { Sidekiq::SortedEntry.new(set, 0, 'jid' => '54321') } it 'queues a job normally at first' do DebouncedWorker.perform_in(60, 'foo', 'bar') set.size.must_equal 1, 'set.size must be 1' end it 'ignores repeat jobs within the debounce time and reschedules' do sorted_entry.expects(:reschedule) DebouncedWorker.perform_in(60, 'foo', 'bar') DebouncedWorker.perform_in(60, 'foo', 'bar') set.size.must_equal 1, 'set.size must be 1' end it 'debounces jobs based on their arguments' do DebouncedWorker.perform_in(60, 'boo', 'far') DebouncedWorker.perform_in(60, 'foo', 'bar') set.size.must_equal 2, 'set.size must be 2' end it 'creates the job immediately when given an instant job' do DebouncedWorker.perform_async('foo', 'bar') set.size.must_equal 0, 'set.size must be 0' end def stub_scheduled_set set.stubs(:find_job).returns(sorted_entry) Sidekiq::Debounce.any_instance.stubs(:scheduled_set).returns(set) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-debounce-1.0.2 | spec/sidekiq/debounce_spec.rb |
sidekiq-debounce-1.0.1 | spec/sidekiq/debounce_spec.rb |
sidekiq-debounce-1.0.0 | spec/sidekiq/debounce_spec.rb |