Skip to content

Commit

Permalink
corrects to styling and deleting some unnecessary specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hkim3163 committed Jun 26, 2023
1 parent e9061cc commit 3e85f78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
14 changes: 2 additions & 12 deletions spec/sidekiq-instrument/client_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
it 'increments the DogStatsD enqueue counter' do
expect(
Sidekiq::Instrument::Statter.dogstatsd
).to receive(:increment).with('sidekiq.enqueue', { tags: ['queue:default', 'worker:my_worker'] }).once
).to receive(:increment).with('sidekiq.enqueue', { tags: ['queue:default', 'worker:my_worker'] }).once
MyWorker.perform_async
end
end
Expand All @@ -52,7 +52,7 @@
end

context 'with WorkerMetrics.enabled true' do
it 'increments the enqueue counter' do
it 'increments the in_queue counter' do
Sidekiq::Instrument::WorkerMetrics.enabled = true
MyOtherWorker.perform_async
expect(Redis.new.hget(worker_metric_name, 'my_other_worker')).to eq('1')
Expand All @@ -75,15 +75,5 @@
expect { MyWorker.perform_async }.not_to raise_error
end
end

context 'when a job fails' do
before do
allow_any_instance_of(MyWorker).to receive(:perform).and_raise('foo')
end

it 're-raises the error' do
expect { MyWorker.perform_async }.to raise_error 'foo'
end
end
end
end
11 changes: 6 additions & 5 deletions spec/sidekiq-instrument/server_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@
end

context 'with WorkerMetrics.enabled true' do
it 'increments the in queue counter' do
it 'decrements the in_queue counter' do
Sidekiq::Instrument::WorkerMetrics.enabled = true
Redis.new.hdel worker_metric_name, 'my_other_worker'
Redis.new.hdel(worker_metric_name, 'my_other_worker')
MyOtherWorker.perform_async
expect(Redis.new.hget(worker_metric_name, 'my_other_worker')).to eq('-1')
end
end

context 'with WorkerMetrics.enabled true and an errored job' do
it 'decrements the in queue counter' do
it 'decrements the in_queue counter' do
Sidekiq::Instrument::WorkerMetrics.enabled = true
MyOtherWorker.perform_async
expect(Redis.new.hget(worker_metric_name, 'my_other_worker')).to eq('-1')
Expand Down Expand Up @@ -103,13 +103,14 @@
end
end

it 'does not increase the redis counter' do
it 'decrements the in_queue counter' do
expect(Redis.new.hget(worker_metric_name, 'my_worker')).to eq(nil)
begin
MyWorker.perform_async
rescue StandardError
nil
end
expect(Redis.new.hget(worker_metric_name, 'my_worker')).to eq('-1')
end

it 're-raises the error' do
Expand All @@ -119,7 +120,7 @@
it 'calls the decrement counter' do
expect(
Sidekiq::Instrument::WorkerMetrics
).to receive(:trace_workers_decrement_counter).with('my_worker').once
).to receive(:trace_workers_decrement_counter).with('my_worker').once
begin
MyWorker.perform_async
rescue StandardError
Expand Down
2 changes: 1 addition & 1 deletion spec/sidekiq-instrument/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
it 'increments the DogStatsD failure counter' do
expect(
Sidekiq::Instrument::Statter.dogstatsd
).to receive(:increment).with('sidekiq.enqueue', expected_dog_options).once
).to receive(:increment).with('sidekiq.enqueue', expected_dog_options).once
expect(Sidekiq::Instrument::Statter.dogstatsd).not_to receive(:time)
begin
MyWorker.perform_async
Expand Down

0 comments on commit 3e85f78

Please sign in to comment.