Sha256: d8e6fa1552681389388d2c41958c14cdf604e2609a62a6840ed8fde61dfb0110

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

require File.expand_path("../spec_helper", __dir__)

RSpec.describe Redstream::Trimmer do
  describe "#run_once" do
    it "trims a stream to the minimum committed id" do
      ids = Array.new(4) do |i|
        redis.xadd(Redstream.stream_key_name("default"), { payload: JSON.dump(value: "message#{i}") })
      end

      redis.set(Redstream.offset_key_name(stream_name: "default", consumer_name: "consumer1"), ids[1])
      redis.set(Redstream.offset_key_name(stream_name: "default", consumer_name: "consumer2"), ids[2])

      trimmer = Redstream::Trimmer.new(
        interval: 5,
        stream_name: "default",
        consumer_names: ["consumer1", "consumer2", "consumer_without_committed_id"]
      )

      trimmer.run_once

      expect(redis.xlen(Redstream.stream_key_name("default"))).to eq(2)
    end

    it "sleeps for the specified time if there's nothing to trim" do
      trimmer = Redstream::Trimmer.new(interval: 1, stream_name: "default", consumer_names: ["unknown_consumer"])
      trimmer.expects(:sleep).with(1).returns(true)
      trimmer.run_once
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
redstream-0.5.0 spec/redstream/trimmer_spec.rb
redstream-0.4.4 spec/redstream/trimmer_spec.rb
redstream-0.4.3 spec/redstream/trimmer_spec.rb
redstream-0.4.2 spec/redstream/trimmer_spec.rb
redstream-0.4.1 spec/redstream/trimmer_spec.rb