sidekiq-status 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +1 -0
- data/lib/sidekiq-status.rb +3 -5
- data/lib/sidekiq-status/version.rb +1 -1
- data/sidekiq-status.gemspec +1 -1
- data/spec/lib/sidekiq-status/client_middleware_spec.rb +10 -10
- data/spec/lib/sidekiq-status/server_middleware_spec.rb +20 -19
- data/spec/lib/sidekiq-status/worker_spec.rb +3 -2
- data/spec/lib/sidekiq-status_spec.rb +74 -67
- data/spec/spec_helper.rb +1 -1
- metadata +4 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d3dd7cc94267c99010ecd9b47129528e1c2a2a12
         | 
| 4 | 
            +
              data.tar.gz: b2fdf88b3ff5717fa202d92652d2b9bae0c40140
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6edd2298f96a0bcbcd3c7dc58426c328f159fd6de092e1764e31cfad2b07c00ba48dc4f7cdadd6e1d0b40c4e9b3c19ffb8f7af2dc33e9378f6e214a306822490
         | 
| 7 | 
            +
              data.tar.gz: f4ed9c45848b094916256730db4f286733e662d3a81735490fe1285d40fea464c9d787c72fad8f17c01ad67b8081eac93ebbd28c717a7939a7479939e7338f9b
         | 
    
        data/CHANGELOG
    CHANGED
    
    
    
        data/lib/sidekiq-status.rb
    CHANGED
    
    | @@ -37,11 +37,9 @@ module Sidekiq::Status | |
| 37 37 | 
             
                alias_method :unschedule, :cancel
         | 
| 38 38 |  | 
| 39 39 | 
             
                STATUS.each do |name|
         | 
| 40 | 
            -
                   | 
| 41 | 
            -
                     | 
| 42 | 
            -
             | 
| 43 | 
            -
                    end
         | 
| 44 | 
            -
                  END
         | 
| 40 | 
            +
                  define_method("#{name}?") do |job_id|
         | 
| 41 | 
            +
                    status(job_id) == name
         | 
| 42 | 
            +
                  end
         | 
| 45 43 | 
             
                end
         | 
| 46 44 |  | 
| 47 45 | 
             
                # Methods for retrieving job completion
         | 
    
        data/sidekiq-status.gemspec
    CHANGED
    
    | @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| | |
| 14 14 | 
             
              gem.require_paths = ['lib']
         | 
| 15 15 | 
             
              gem.version       = Sidekiq::Status::VERSION
         | 
| 16 16 |  | 
| 17 | 
            -
              gem.add_dependency                  'sidekiq', '>= 2.7', '< 3. | 
| 17 | 
            +
              gem.add_dependency                  'sidekiq', '>= 2.7', '< 3.4'
         | 
| 18 18 | 
             
              gem.add_development_dependency      'rake'
         | 
| 19 19 | 
             
              gem.add_development_dependency      'rspec'
         | 
| 20 20 | 
             
            end
         | 
| @@ -10,30 +10,30 @@ describe Sidekiq::Status::ClientMiddleware do | |
| 10 10 |  | 
| 11 11 | 
             
              describe "#call" do
         | 
| 12 12 | 
             
                it "sets queued status" do
         | 
| 13 | 
            -
                  SecureRandom. | 
| 14 | 
            -
                  StubJob.perform_async(:arg1 => 'val1'). | 
| 15 | 
            -
                  redis.hget(job_id, :status). | 
| 16 | 
            -
                  Sidekiq::Status::queued?(job_id). | 
| 13 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 14 | 
            +
                  expect(StubJob.perform_async(:arg1 => 'val1')).to eq(job_id)
         | 
| 15 | 
            +
                  expect(redis.hget(job_id, :status)).to eq('queued')
         | 
| 16 | 
            +
                  expect(Sidekiq::Status::queued?(job_id)).to be_truthy
         | 
| 17 17 | 
             
                end
         | 
| 18 18 |  | 
| 19 19 | 
             
                it "sets status hash ttl" do
         | 
| 20 | 
            -
                  SecureRandom. | 
| 21 | 
            -
                  StubJob.perform_async(:arg1 => 'val1'). | 
| 22 | 
            -
                  (1..Sidekiq::Status::DEFAULT_EXPIRY). | 
| 20 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 21 | 
            +
                  expect(StubJob.perform_async(:arg1 => 'val1')).to eq(job_id)
         | 
| 22 | 
            +
                  expect(1..Sidekiq::Status::DEFAULT_EXPIRY).to cover redis.ttl(job_id)
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 25 | 
             
                context "when redis_pool passed" do
         | 
| 26 26 | 
             
                  it "uses redis_pool" do
         | 
| 27 27 | 
             
                    redis_pool = double(:redis_pool)
         | 
| 28 | 
            -
                    redis_pool. | 
| 29 | 
            -
                    Sidekiq. | 
| 28 | 
            +
                    allow(redis_pool).to receive(:with)
         | 
| 29 | 
            +
                    expect(Sidekiq).to_not receive(:redis)
         | 
| 30 30 | 
             
                    Sidekiq::Status::ClientMiddleware.new.call(StubJob, {'jid' => SecureRandom.hex}, :queued, redis_pool) do end
         | 
| 31 31 | 
             
                  end
         | 
| 32 32 | 
             
                end
         | 
| 33 33 |  | 
| 34 34 | 
             
                context "when redis_pool is not passed" do
         | 
| 35 35 | 
             
                  it "uses Sidekiq.redis" do
         | 
| 36 | 
            -
                    Sidekiq. | 
| 36 | 
            +
                    allow(Sidekiq).to receive(:redis)
         | 
| 37 37 | 
             
                    Sidekiq::Status::ClientMiddleware.new.call(StubJob, {'jid' => SecureRandom.hex}, :queued) do end
         | 
| 38 38 | 
             
                  end
         | 
| 39 39 | 
             
                end
         | 
| @@ -13,54 +13,55 @@ describe Sidekiq::Status::ServerMiddleware do | |
| 13 13 | 
             
              describe "#call" do
         | 
| 14 14 | 
             
                it "sets working/complete status" do
         | 
| 15 15 | 
             
                  thread = confirmations_thread 4, "status_updates", "job_messages_#{job_id}"
         | 
| 16 | 
            -
                  SecureRandom. | 
| 16 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 17 17 | 
             
                  start_server do
         | 
| 18 | 
            -
                    ConfirmationJob.perform_async(:arg1 => 'val1'). | 
| 19 | 
            -
                    thread.value. | 
| 18 | 
            +
                    expect(ConfirmationJob.perform_async(:arg1 => 'val1')).to eq(job_id)
         | 
| 19 | 
            +
                    expect(thread.value).to eq([job_id, job_id,
         | 
| 20 20 | 
             
                                            "while in #perform, status = working",
         | 
| 21 | 
            -
                                            job_id]
         | 
| 21 | 
            +
                                            job_id])
         | 
| 22 22 | 
             
                  end
         | 
| 23 | 
            -
                  redis.hget(job_id, :status). | 
| 24 | 
            -
                  Sidekiq::Status::complete?(job_id). | 
| 23 | 
            +
                  expect(redis.hget(job_id, :status)).to eq('complete')
         | 
| 24 | 
            +
                  expect(Sidekiq::Status::complete?(job_id)).to be_truthy
         | 
| 25 25 | 
             
                end
         | 
| 26 26 |  | 
| 27 27 | 
             
                it "sets failed status" do
         | 
| 28 | 
            -
                  SecureRandom. | 
| 28 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 29 29 | 
             
                  start_server do
         | 
| 30 | 
            -
                    capture_status_updates(3) {
         | 
| 31 | 
            -
                      FailingJob.perform_async. | 
| 32 | 
            -
                    }. | 
| 30 | 
            +
                    expect(capture_status_updates(3) {
         | 
| 31 | 
            +
                      expect(FailingJob.perform_async).to eq(job_id)
         | 
| 32 | 
            +
                    }).to eq([job_id]*3)
         | 
| 33 33 | 
             
                  end
         | 
| 34 | 
            -
                  redis.hget(job_id, :status). | 
| 35 | 
            -
                  Sidekiq::Status::failed?(job_id). | 
| 34 | 
            +
                  expect(redis.hget(job_id, :status)).to eq('failed')
         | 
| 35 | 
            +
                  expect(Sidekiq::Status::failed?(job_id)).to be_truthy
         | 
| 36 36 | 
             
                end
         | 
| 37 37 |  | 
| 38 38 | 
             
                it "sets status hash ttl" do
         | 
| 39 | 
            -
                  SecureRandom. | 
| 40 | 
            -
                  StubJob.perform_async(:arg1 => 'val1'). | 
| 41 | 
            -
                  (1..Sidekiq::Status::DEFAULT_EXPIRY). | 
| 39 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 40 | 
            +
                  expect(StubJob.perform_async(:arg1 => 'val1')).to eq(job_id)
         | 
| 41 | 
            +
                  expect(1..Sidekiq::Status::DEFAULT_EXPIRY).to cover redis.ttl(job_id)
         | 
| 42 42 | 
             
                end
         | 
| 43 43 | 
             
              end
         | 
| 44 44 |  | 
| 45 45 | 
             
              describe ":expiration parameter" do
         | 
| 46 46 | 
             
                let(:huge_expiration) { Sidekiq::Status::DEFAULT_EXPIRY * 100 }
         | 
| 47 47 | 
             
                before do
         | 
| 48 | 
            -
                  SecureRandom. | 
| 48 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 49 49 | 
             
                end
         | 
| 50 | 
            +
             | 
| 50 51 | 
             
                it "overwrites default expiry value" do
         | 
| 51 52 | 
             
                  start_server(:expiration => huge_expiration) do
         | 
| 52 53 | 
             
                    StubJob.perform_async(:arg1 => 'val1')
         | 
| 53 54 | 
             
                  end
         | 
| 54 | 
            -
                  ((Sidekiq::Status::DEFAULT_EXPIRY+1)..huge_expiration). | 
| 55 | 
            +
                  expect((Sidekiq::Status::DEFAULT_EXPIRY+1)..huge_expiration).to cover redis.ttl(job_id)
         | 
| 55 56 | 
             
                end
         | 
| 56 57 |  | 
| 57 58 | 
             
                it "can be overwritten by worker expiration method" do
         | 
| 58 59 | 
             
                  overwritten_expiration = huge_expiration * 100
         | 
| 59 | 
            -
                  StubJob. | 
| 60 | 
            +
                  allow_any_instance_of(StubJob).to receive(:expiration).and_return(overwritten_expiration)
         | 
| 60 61 | 
             
                  start_server(:expiration => huge_expiration) do
         | 
| 61 62 | 
             
                    StubJob.perform_async(:arg1 => 'val1')
         | 
| 62 63 | 
             
                  end
         | 
| 63 | 
            -
                  ((huge_expiration+1)..overwritten_expiration). | 
| 64 | 
            +
                  expect((huge_expiration+1)..overwritten_expiration).to cover redis.ttl(job_id)
         | 
| 64 65 | 
             
                end
         | 
| 65 66 | 
             
              end
         | 
| 66 67 | 
             
            end
         | 
| @@ -6,13 +6,14 @@ describe Sidekiq::Status::Worker do | |
| 6 6 |  | 
| 7 7 | 
             
              describe ".perform_async" do
         | 
| 8 8 | 
             
                it "generates and returns job id" do
         | 
| 9 | 
            -
                  SecureRandom. | 
| 10 | 
            -
                  StubJob.perform_async(). | 
| 9 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 10 | 
            +
                  expect(StubJob.perform_async()).to eq(job_id)
         | 
| 11 11 | 
             
                end
         | 
| 12 12 | 
             
              end
         | 
| 13 13 |  | 
| 14 14 | 
             
              describe ".expiration" do
         | 
| 15 15 | 
             
                subject { StubJob.new }
         | 
| 16 | 
            +
                
         | 
| 16 17 | 
             
                it "allows to set/get expiration" do
         | 
| 17 18 | 
             
                  expect(subject.expiration).to be_nil
         | 
| 18 19 | 
             
                  subject.expiration = :val
         | 
| @@ -16,105 +16,109 @@ describe Sidekiq::Status do | |
| 16 16 |  | 
| 17 17 | 
             
              describe ".status, .working?, .complete?" do
         | 
| 18 18 | 
             
                it "gets job status by id as symbol" do
         | 
| 19 | 
            -
                  SecureRandom. | 
| 19 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 20 20 |  | 
| 21 21 | 
             
                  start_server do
         | 
| 22 | 
            -
                    capture_status_updates(2) {
         | 
| 23 | 
            -
                      LongJob.perform_async(1). | 
| 24 | 
            -
                    }. | 
| 25 | 
            -
                    Sidekiq::Status.status(job_id). | 
| 26 | 
            -
                    Sidekiq::Status.working?(job_id). | 
| 27 | 
            -
                    Sidekiq::Status::queued?(job_id). | 
| 28 | 
            -
                    Sidekiq::Status::failed?(job_id | 
| 29 | 
            -
                    Sidekiq::Status::complete?(job_id). | 
| 30 | 
            -
                    Sidekiq::Status::stopped?(job_id). | 
| 22 | 
            +
                    expect(capture_status_updates(2) {
         | 
| 23 | 
            +
                      expect(LongJob.perform_async(1)).to eq(job_id)
         | 
| 24 | 
            +
                    }).to eq([job_id]*2)
         | 
| 25 | 
            +
                    expect(Sidekiq::Status.status(job_id)).to eq(:working)
         | 
| 26 | 
            +
                    expect(Sidekiq::Status.working?(job_id)).to be_truthy
         | 
| 27 | 
            +
                    expect(Sidekiq::Status::queued?(job_id)).to be_falsey
         | 
| 28 | 
            +
                    expect(Sidekiq::Status::failed?(job_id)).to be_falsey
         | 
| 29 | 
            +
                    expect(Sidekiq::Status::complete?(job_id)).to be_falsey
         | 
| 30 | 
            +
                    expect(Sidekiq::Status::stopped?(job_id)).to be_falsey
         | 
| 31 31 | 
             
                  end
         | 
| 32 | 
            -
                  Sidekiq::Status.status(job_id). | 
| 33 | 
            -
                  Sidekiq::Status.complete?(job_id). | 
| 32 | 
            +
                  expect(Sidekiq::Status.status(job_id)).to eq(:complete)
         | 
| 33 | 
            +
                  expect(Sidekiq::Status.complete?(job_id)).to be_truthy
         | 
| 34 34 | 
             
                end
         | 
| 35 35 | 
             
              end
         | 
| 36 36 |  | 
| 37 37 | 
             
              describe ".get" do
         | 
| 38 38 | 
             
                it "gets a single value from data hash as string" do
         | 
| 39 | 
            -
                  SecureRandom. | 
| 39 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 40 40 |  | 
| 41 41 | 
             
                  start_server do
         | 
| 42 | 
            -
                    capture_status_updates(3) {
         | 
| 43 | 
            -
                      DataJob.perform_async. | 
| 44 | 
            -
                    }. | 
| 45 | 
            -
                    Sidekiq::Status.get(job_id, :status). | 
| 42 | 
            +
                    expect(capture_status_updates(3) {
         | 
| 43 | 
            +
                      expect(DataJob.perform_async).to eq(job_id)
         | 
| 44 | 
            +
                    }).to eq([job_id]*3)
         | 
| 45 | 
            +
                    expect(Sidekiq::Status.get(job_id, :status)).to eq('working')
         | 
| 46 46 | 
             
                  end
         | 
| 47 | 
            -
                  Sidekiq::Status.get(job_id, :data). | 
| 47 | 
            +
                  expect(Sidekiq::Status.get(job_id, :data)).to eq('meow')
         | 
| 48 48 | 
             
                end
         | 
| 49 49 | 
             
              end
         | 
| 50 50 |  | 
| 51 51 | 
             
              describe ".at, .total, .pct_complete, .message" do
         | 
| 52 52 | 
             
                it "should return job progress with correct type to it" do
         | 
| 53 | 
            -
                  SecureRandom. | 
| 53 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 54 54 |  | 
| 55 55 | 
             
                  start_server do
         | 
| 56 | 
            -
                    capture_status_updates(3) {
         | 
| 57 | 
            -
                      ProgressJob.perform_async. | 
| 58 | 
            -
                    }. | 
| 56 | 
            +
                    expect(capture_status_updates(3) {
         | 
| 57 | 
            +
                      expect(ProgressJob.perform_async).to eq(job_id)
         | 
| 58 | 
            +
                    }).to eq([job_id]*3)
         | 
| 59 59 | 
             
                  end
         | 
| 60 | 
            -
                  Sidekiq::Status.at(job_id). | 
| 61 | 
            -
                  Sidekiq::Status.total(job_id). | 
| 62 | 
            -
                   | 
| 63 | 
            -
                  Sidekiq::Status. | 
| 60 | 
            +
                  expect(Sidekiq::Status.at(job_id)).to be(100)
         | 
| 61 | 
            +
                  expect(Sidekiq::Status.total(job_id)).to be(500)
         | 
| 62 | 
            +
                  # It returns a float therefor we need eq()
         | 
| 63 | 
            +
                  expect(Sidekiq::Status.pct_complete(job_id)).to eq(20)
         | 
| 64 | 
            +
                  expect(Sidekiq::Status.message(job_id)).to eq('howdy, partner?')
         | 
| 64 65 | 
             
                end
         | 
| 65 66 | 
             
              end
         | 
| 66 67 |  | 
| 67 68 | 
             
              describe ".get_all" do
         | 
| 68 69 | 
             
                it "gets the job hash by id" do
         | 
| 69 | 
            -
                  SecureRandom. | 
| 70 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 70 71 |  | 
| 71 72 | 
             
                  start_server do
         | 
| 72 | 
            -
                    capture_status_updates(2) {
         | 
| 73 | 
            -
                      LongJob.perform_async(1). | 
| 74 | 
            -
                    }. | 
| 75 | 
            -
                    (hash = Sidekiq::Status.get_all(job_id)). | 
| 76 | 
            -
                    hash. | 
| 73 | 
            +
                    expect(capture_status_updates(2) {
         | 
| 74 | 
            +
                      expect(LongJob.perform_async(1)).to eq(job_id)
         | 
| 75 | 
            +
                    }).to eq([job_id]*2)
         | 
| 76 | 
            +
                    expect(hash = Sidekiq::Status.get_all(job_id)).to include 'status' => 'working'
         | 
| 77 | 
            +
                    expect(hash).to include 'update_time'
         | 
| 77 78 | 
             
                  end
         | 
| 78 | 
            -
                  (hash = Sidekiq::Status.get_all(job_id)). | 
| 79 | 
            -
                  hash. | 
| 79 | 
            +
                  expect(hash = Sidekiq::Status.get_all(job_id)).to include 'status' => 'complete'
         | 
| 80 | 
            +
                  expect(hash).to include 'update_time'
         | 
| 80 81 | 
             
                end
         | 
| 81 82 | 
             
              end
         | 
| 82 83 |  | 
| 83 84 | 
             
              describe ".cancel" do
         | 
| 84 85 | 
             
                it "cancels a job by id" do
         | 
| 85 | 
            -
                  SecureRandom. | 
| 86 | 
            +
                  allow(SecureRandom).to receive(:hex).twice.and_return(job_id, job_id_1)
         | 
| 86 87 | 
             
                  start_server do
         | 
| 87 88 | 
             
                    job = LongJob.perform_in(3600)
         | 
| 88 | 
            -
                    job. | 
| 89 | 
            +
                    expect(job).to eq(job_id)
         | 
| 89 90 | 
             
                    second_job = LongJob.perform_in(3600)
         | 
| 90 | 
            -
                    second_job. | 
| 91 | 
            +
                    expect(second_job).to eq(job_id_1)
         | 
| 91 92 |  | 
| 92 93 | 
             
                    initial_schedule = redis.zrange "schedule", 0, -1, {withscores: true}
         | 
| 93 | 
            -
                    initial_schedule.size. | 
| 94 | 
            -
                    initial_schedule.select {|scheduled_job| JSON.parse(scheduled_job[0])["jid"] == job_id }.size. | 
| 94 | 
            +
                    expect(initial_schedule.size).to  be(2)
         | 
| 95 | 
            +
                    expect(initial_schedule.select {|scheduled_job| JSON.parse(scheduled_job[0])["jid"] == job_id }.size).to be(1)
         | 
| 95 96 |  | 
| 96 | 
            -
                    Sidekiq::Status.unschedule(job_id). | 
| 97 | 
            -
                     | 
| 97 | 
            +
                    expect(Sidekiq::Status.unschedule(job_id)).to be_truthy
         | 
| 98 | 
            +
                    # Unused, therefore unfound => false
         | 
| 99 | 
            +
                    expect(Sidekiq::Status.cancel(unused_id)).to be_falsey
         | 
| 98 100 |  | 
| 99 101 | 
             
                    remaining_schedule = redis.zrange "schedule", 0, -1, {withscores: true}
         | 
| 100 | 
            -
                    remaining_schedule.size. | 
| 101 | 
            -
                    remaining_schedule.select {|scheduled_job| JSON.parse(scheduled_job[0])["jid"] == job_id }.size. | 
| 102 | 
            +
                    expect(remaining_schedule.size).to be(initial_schedule.size - 1)
         | 
| 103 | 
            +
                    expect(remaining_schedule.select {|scheduled_job| JSON.parse(scheduled_job[0])["jid"] == job_id }.size).to be(0)
         | 
| 102 104 | 
             
                  end
         | 
| 103 105 | 
             
                end
         | 
| 104 106 |  | 
| 105 107 | 
             
                it "does not cancel a job with correct id but wrong time" do
         | 
| 106 | 
            -
                  SecureRandom. | 
| 108 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
         | 
| 107 109 | 
             
                  start_server do
         | 
| 108 110 | 
             
                    scheduled_time = Time.now.to_i + 3600
         | 
| 109 111 | 
             
                    returned_job_id = LongJob.perform_at(scheduled_time)
         | 
| 110 | 
            -
                    returned_job_id. | 
| 112 | 
            +
                    expect(returned_job_id).to eq(job_id)
         | 
| 111 113 |  | 
| 112 114 | 
             
                    initial_schedule = redis.zrange "schedule", 0, -1, {withscores: true}
         | 
| 113 | 
            -
                    initial_schedule.size. | 
| 114 | 
            -
                     | 
| 115 | 
            -
                    ( | 
| 116 | 
            -
                     | 
| 117 | 
            -
                     | 
| 115 | 
            +
                    expect(initial_schedule.size).to be(1)
         | 
| 116 | 
            +
                    # wrong time, therefore unfound => false
         | 
| 117 | 
            +
                    expect(Sidekiq::Status.cancel(returned_job_id, (scheduled_time + 1))).to be_falsey
         | 
| 118 | 
            +
                    expect((redis.zrange "schedule", 0, -1, {withscores: true}).size).to be(1)
         | 
| 119 | 
            +
                    # same id, same time, deletes
         | 
| 120 | 
            +
                    expect(Sidekiq::Status.cancel(returned_job_id, (scheduled_time))).to be_truthy
         | 
| 121 | 
            +
                    expect(redis.zrange "schedule", 0, -1, {withscores: true}).to be_empty
         | 
| 118 122 | 
             
                  end
         | 
| 119 123 | 
             
                end
         | 
| 120 124 | 
             
              end
         | 
| @@ -130,13 +134,13 @@ describe Sidekiq::Status do | |
| 130 134 | 
             
                end
         | 
| 131 135 |  | 
| 132 136 | 
             
                it "retries failed jobs" do
         | 
| 133 | 
            -
                  SecureRandom. | 
| 137 | 
            +
                  allow(SecureRandom).to receive(:hex).once.and_return(retried_job_id)
         | 
| 134 138 | 
             
                  start_server do
         | 
| 135 | 
            -
                    capture_status_updates(5) {
         | 
| 136 | 
            -
                      RetriedJob.perform_async(). | 
| 137 | 
            -
                    }. | 
| 139 | 
            +
                    expect(capture_status_updates(5) {
         | 
| 140 | 
            +
                      expect(RetriedJob.perform_async()).to eq(retried_job_id)
         | 
| 141 | 
            +
                    }).to eq([retried_job_id] * 5)
         | 
| 138 142 | 
             
                  end
         | 
| 139 | 
            -
                  Sidekiq::Status.status(retried_job_id). | 
| 143 | 
            +
                  expect(Sidekiq::Status.status(retried_job_id)).to eq(:complete)
         | 
| 140 144 | 
             
                end
         | 
| 141 145 |  | 
| 142 146 | 
             
                context ":expiration param" do
         | 
| @@ -151,8 +155,10 @@ describe Sidekiq::Status do | |
| 151 155 |  | 
| 152 156 | 
             
                  it "allow to overwrite :expiration parameter by .expiration method from worker" do
         | 
| 153 157 | 
             
                    overwritten_expiration = expiration_param * 100
         | 
| 154 | 
            -
                    NoStatusConfirmationJob. | 
| 155 | 
            -
             | 
| 158 | 
            +
                    allow_any_instance_of(NoStatusConfirmationJob).to receive(:expiration).
         | 
| 159 | 
            +
                      and_return(overwritten_expiration)
         | 
| 160 | 
            +
                    allow_any_instance_of(StubJob).to receive(:expiration).
         | 
| 161 | 
            +
                      and_return(overwritten_expiration)
         | 
| 156 162 | 
             
                    run_2_jobs!
         | 
| 157 163 | 
             
                    expect_2_jobs_are_done_and_status_eq :complete
         | 
| 158 164 | 
             
                    expect_2_jobs_ttl_covers (expiration_param+1)..overwritten_expiration
         | 
| @@ -160,29 +166,30 @@ describe Sidekiq::Status do | |
| 160 166 | 
             
                end
         | 
| 161 167 |  | 
| 162 168 | 
             
                def seed_secure_random_with_job_ids
         | 
| 163 | 
            -
                  SecureRandom. | 
| 169 | 
            +
                  allow(SecureRandom).to receive(:hex).exactly(4).times.
         | 
| 170 | 
            +
                    and_return(plain_sidekiq_job_id, plain_sidekiq_job_id, job_id_1, job_id_1)
         | 
| 164 171 | 
             
                end
         | 
| 165 172 |  | 
| 166 173 | 
             
                def run_2_jobs!
         | 
| 167 174 | 
             
                  start_server(:expiration => expiration_param) do
         | 
| 168 | 
            -
                    capture_status_updates(12) {
         | 
| 169 | 
            -
                      StubJob.perform_async. | 
| 175 | 
            +
                    expect(capture_status_updates(12) {
         | 
| 176 | 
            +
                      expect(StubJob.perform_async).to eq(plain_sidekiq_job_id)
         | 
| 170 177 | 
             
                      NoStatusConfirmationJob.perform_async(1)
         | 
| 171 | 
            -
                      StubJob.perform_async. | 
| 178 | 
            +
                      expect(StubJob.perform_async).to eq(job_id_1)
         | 
| 172 179 | 
             
                      NoStatusConfirmationJob.perform_async(2)
         | 
| 173 | 
            -
                    }. | 
| 180 | 
            +
                    }).to match_array([plain_sidekiq_job_id, job_id_1] * 6)
         | 
| 174 181 | 
             
                  end
         | 
| 175 182 | 
             
                end
         | 
| 176 183 |  | 
| 177 184 | 
             
                def expect_2_jobs_ttl_covers(range)
         | 
| 178 | 
            -
                  range. | 
| 179 | 
            -
                  range. | 
| 185 | 
            +
                  expect(range).to cover redis.ttl(plain_sidekiq_job_id)
         | 
| 186 | 
            +
                  expect(range).to cover redis.ttl(job_id_1)
         | 
| 180 187 | 
             
                end
         | 
| 181 188 |  | 
| 182 189 | 
             
                def expect_2_jobs_are_done_and_status_eq(status)
         | 
| 183 | 
            -
                  redis.mget('NoStatusConfirmationJob_1', 'NoStatusConfirmationJob_2'). | 
| 184 | 
            -
                  Sidekiq::Status.status(plain_sidekiq_job_id). | 
| 185 | 
            -
                  Sidekiq::Status.status(job_id_1). | 
| 190 | 
            +
                  expect(redis.mget('NoStatusConfirmationJob_1', 'NoStatusConfirmationJob_2')).to eq(%w(done)*2)
         | 
| 191 | 
            +
                  expect(Sidekiq::Status.status(plain_sidekiq_job_id)).to eq(status)
         | 
| 192 | 
            +
                  expect(Sidekiq::Status.status(job_id_1)).to eq(status)
         | 
| 186 193 | 
             
                end
         | 
| 187 194 | 
             
              end
         | 
| 188 195 |  | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -50,6 +50,7 @@ def start_server(server_middleware_options={}) | |
| 50 50 | 
             
                $stderr.reopen File::NULL, 'w'
         | 
| 51 51 | 
             
                require 'sidekiq/cli'
         | 
| 52 52 | 
             
                Sidekiq.options[:queues] << 'default'
         | 
| 53 | 
            +
                Sidekiq.options[:require] =  File.expand_path('../support/test_jobs.rb', __FILE__)
         | 
| 53 54 | 
             
                Sidekiq.configure_server do |config|
         | 
| 54 55 | 
             
                  config.redis = Sidekiq::RedisConnection.create
         | 
| 55 56 | 
             
                  config.server_middleware do |chain|
         | 
| @@ -60,7 +61,6 @@ def start_server(server_middleware_options={}) | |
| 60 61 | 
             
              end
         | 
| 61 62 |  | 
| 62 63 | 
             
              yield
         | 
| 63 | 
            -
             | 
| 64 64 | 
             
              sleep 0.1
         | 
| 65 65 | 
             
              Process.kill 'TERM', pid
         | 
| 66 66 | 
             
              Timeout::timeout(10) { Process.wait pid } rescue Timeout::Error
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sidekiq-status
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.5. | 
| 4 | 
            +
              version: 0.5.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Evgeniy Tsvigun
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-08-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: sidekiq
         | 
| @@ -19,7 +19,7 @@ dependencies: | |
| 19 19 | 
             
                    version: '2.7'
         | 
| 20 20 | 
             
                - - "<"
         | 
| 21 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            -
                    version: '3. | 
| 22 | 
            +
                    version: '3.4'
         | 
| 23 23 | 
             
              type: :runtime
         | 
| 24 24 | 
             
              prerelease: false
         | 
| 25 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -29,7 +29,7 @@ dependencies: | |
| 29 29 | 
             
                    version: '2.7'
         | 
| 30 30 | 
             
                - - "<"
         | 
| 31 31 | 
             
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            -
                    version: '3. | 
| 32 | 
            +
                    version: '3.4'
         | 
| 33 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 34 34 | 
             
              name: rake
         | 
| 35 35 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -122,4 +122,3 @@ test_files: | |
| 122 122 | 
             
            - spec/lib/sidekiq-status_spec.rb
         | 
| 123 123 | 
             
            - spec/spec_helper.rb
         | 
| 124 124 | 
             
            - spec/support/test_jobs.rb
         | 
| 125 | 
            -
            has_rdoc: 
         |