spec/gc_spec.rb in wayfarer-0.4.6 vs spec/gc_spec.rb in wayfarer-0.4.7
- old
+ new
@@ -1,59 +1,17 @@
# frozen_string_literal: true
require "spec_helpers"
-describe Wayfarer::GC, redis: true do
- include Wayfarer::Redis::Connection
+describe Wayfarer::GC, "::run", redis: true do
+ let(:task) { build(:task, :redis_pool) }
+ let(:barrier) { instance_double(Wayfarer::Redis::Barrier) }
- let(:task) { build(:task) }
- subject(:gc) { described_class.new(task) }
+ subject(:run) { described_class.run(task) }
- before do
- task.metadata.job = spy
- task.barrier.seen?(task.url)
- end
+ it "resets barrier and counter" do
+ expect(barrier).to receive(:reset!)
+ expect(Wayfarer::Redis::Barrier).to receive(:new).with(task).and_return(barrier)
- 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(task.metadata.job).to receive(:run_callbacks).with(:batch).exactly(:once)
- gc.run
- 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(task.metadata.job).not_to receive(:run_callbacks).with(:batch)
- gc.run
- end
- end
+ run
end
end