Sha256: 4c7a56a2a616c3d4c7e5568eb8cb19c734f75539ab43ea24bdebfea1760050a5

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

require 'sidekiq/restart/command'

describe "Sidekiq::Restart::Command" do
  let(:sidekiq) { double "Sidekiq" }
  let(:command) { Sidekiq::Restart::Command.new sidekiq }

  describe '#run' do
    let(:id)    { "my_id" }

    before do
      allow(sidekiq).to receive(:redis).and_yield(redis)
    end

    context "theres a worker with id" do
      let(:redis) { instance_double "Redis", get: json, del: nil, srem: nil }
      let(:data)  { { 'payload' => msg } }; let(:json) { double }; let(:msg) { double }

      before do
        class_double("Sidekiq::Client", push: nil).as_stubbed_const
        allow(sidekiq).to receive(:load_json).and_return(data)
      end

      it 'uses sidekiqs redis instance' do
        expect(sidekiq).to receive(:redis).and_yield(redis)
        command.run id
      end

      it 'retrieves the job details' do
        expect(redis).to receive(:get).with("worker:my_id")
        expect(sidekiq).to receive(:load_json).with(json)
        command.run id
      end

      it 'requeues the job' do
        expect(Sidekiq::Client).to receive(:push).with(msg)
        command.run id
      end

      it 'cleans up the old worker details' do
        expect(redis).to receive(:srem).with("workers", id)
        expect(redis).to receive(:del).with("worker:my_id")
        expect(redis).to receive(:del).with("worker:my_id:started")
        command.run id
      end
    end

    context "no such worker exists" do
      let(:redis) { instance_double "Redis", get: nil }

      it 'uses sidekiqs redis instance' do
        expect(sidekiq).to receive(:redis).and_yield(redis)
        command.run id
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-restart-0.0.1 spec/unit/sidekiq/restart/command_spec.rb