Sha256: d7bf83047c47b3d29c1f682312fc8504f29bbb6ba8ab3d7774a50a78247268a7

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Sidekiq::Grouping::Redis do
  subject(:redis_service) { described_class.new }

  let(:queue_name)    { "my_queue" }
  let(:key)           { "batching:#{queue_name}" }
  let(:unique_key)    { "batching:#{queue_name}:unique_messages" }

  describe "#push_msg" do
    it "adds message to queue", :aggregate_failures do
      redis_service.push_msg(queue_name, "My message")
      expect(redis { |c| c.llen key }).to eq 1
      expect(redis { |c| c.lrange key, 0, 1 }).to eq ["My message"]
      expect(redis { |c| c.smembers unique_key }).to eq []
    end

    it "remembers unique message if specified" do
      redis_service.push_msg(queue_name, "My message", remember_unique: true)
      expect(redis { |c| c.smembers unique_key }).to eq ["My message"]
    end
  end

  describe "#pluck" do
    it "removes messages from queue" do
      redis_service.push_msg(queue_name, "Message 1")
      redis_service.push_msg(queue_name, "Message 2")
      redis_service.pluck(queue_name, 2)
      expect(redis { |c| c.llen key }).to eq 0
    end

    it "forgets unique messages", :aggregate_failures do
      redis_service.push_msg(queue_name, "Message 1", remember_unique: true)
      redis_service.push_msg(queue_name, "Message 2", remember_unique: true)
      expect(redis { |c| c.scard unique_key }).to eq 2
      redis_service.pluck(queue_name, 2)
      expect(redis { |c| c.smembers unique_key }).to eq []
    end
  end

  private

  def redis(&block)
    Sidekiq.redis(&block)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-grouping-1.2.0 spec/modules/redis_spec.rb