Sha256: d1472576b9d0465d13f2ca7184a6fc9b5d54050af56539fae92600f7dcd950a8

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require "spec_helpers"

describe Wayfarer::GC, redis: true do
  include Wayfarer::Redis::Connection

  let(:task) { build(:task) }
  let(:klass) { Class.new(Wayfarer::Base) }
  let(:job) { klass.new }
  subject(:gc) { Wayfarer::GC.new(job) }

  before do
    job.arguments = [task]
    task.barrier.seen?(task.url)
  end

  describe "#run" do
    context "when counter reaches 0" do
      before { task.counter.increment }

      it "resets the barrier" do
        expect {
          gc.run
        }.to change { redis { |conn| conn.exists?(task.barrier.redis_key) } }.to(false)
      end

      it "resets the counter" do
        expect {
          gc.run
        }.to change { redis { |conn| conn.exists?(task.counter.redis_key) } }.to(false)
      end

      it "runs after batch callbacks" do
        expect { |spy|
          klass.after_batch(&spy)
          gc.run
        }.to yield_control
      end
    end

    context "when counter does not reach 0" do
      before { 2.times { task.counter.increment } }

      it "does not reset the barrier" do
        expect {
          gc.run
        }.not_to(change { redis { |conn| conn.exists?(task.barrier.redis_key) } })
      end

      it "does not reset the counter" do
        expect {
          gc.run
        }.not_to(change { redis { |conn| conn.exists?(task.counter.redis_key) } })
      end

      it "does not run after batch callbacks" do
        expect(klass).not_to receive(:run_after_batch_callbacks)
        gc.run
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wayfarer-0.4.3 spec/gc_spec.rb
wayfarer-0.4.2 spec/gc_spec.rb
wayfarer-0.4.1 spec/gc_spec.rb