Sha256: 53f99b8c8a139f8e3f961d1f1b28d2b36c281e0585f79005aeccffa1d46f927f
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
require "spec_helper" describe Sidekiq::Merger::Middleware do subject { described_class.new } let(:flusher) { Sidekiq::Merger::Flusher.new(Sidekiq.logger) } let(:queue) { "queue" } let(:now) { Time.now } let(:options) { { key: -> (args) { "key" } } } let(:worker_class) do local_options = options Class.new do include Sidekiq::Worker sidekiq_options merger: local_options def self.name "name" end def perform(*args) end end end before :example do allow(Object).to receive(:const_get).with("Name").and_return worker_class end describe "#call" do it "adds the args to the merge" do subject.call(worker_class, { "args" => [1, 2, 3], "at" => now + 10.seconds }, queue) {} subject.call(worker_class, { "args" => [2, 3, 4], "at" => now + 15.seconds }, queue) {} flusher.flush expect(worker_class.jobs.size).to eq 0 Timecop.travel(10.seconds) flusher.flush expect(worker_class.jobs.size).to eq 1 job = worker_class.jobs[0] expect(job["queue"]).to eq queue expect(job["args"]).to contain_exactly [1, 2, 3], [2, 3, 4] end context "without at msg" do it "peforms now with brackets" do expect { |b| subject.call(worker_class, { "args" => [1, 2, 3] }, queue, &b) }.to yield_with_args(worker_class, { "args" => [[1, 2, 3]] }, queue, anything) flusher.flush expect(worker_class.jobs.size).to eq 0 end context "merged msgs" do it "performs now" do expect { |b| subject.call(worker_class, { "args" => [[1, 2, 3]], "merged" => true }, queue, &b) }.to yield_with_args(worker_class, { "args" => [[1, 2, 3]] }, queue, anything) flusher.flush expect(worker_class.jobs.size).to eq 0 end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-merger-0.0.6 | spec/sidekiq/merger/middleware_spec.rb |
sidekiq-merger-0.0.5 | spec/sidekiq/merger/middleware_spec.rb |
sidekiq-merger-0.0.4 | spec/sidekiq/merger/middleware_spec.rb |