Skip to content

Commit cf47949

Browse files
committed
Remove timecop
1 parent b8b233d commit cf47949

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

spec/unit/lib/delayed_job_plugins/delayed_jobs_metrics_spec.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
allow(prometheus).to receive(:update_histogram_metric)
1010
end
1111

12+
it 'loads the plugin' do
13+
expect(Delayed::Worker.plugins).to include(DelayedJobMetrics::Plugin)
14+
end
15+
1216
it 'processes a job and updates Prometheus metrics with simulated time delay' do
1317
Timecop.freeze(Time.now) do
1418
events_cleanup_job = VCAP::CloudController::Jobs::Runtime::EventsCleanup.new(10_000)
@@ -17,23 +21,22 @@
1721
events_cleanup_job = Delayed::Job.last
1822
expect(events_cleanup_job).not_to be_nil
1923

20-
Timecop.travel(10.seconds) do
21-
worker = Delayed::Worker.new
22-
worker.name = 'test_worker'
23-
worker.work_off(1)
24-
25-
expect(prometheus).to have_received(:update_histogram_metric).with(
26-
:cc_job_pickup_delay_seconds,
27-
be_within(0.5).of(10.0),
28-
labels: { queue: VCAP::CloudController::Jobs::Queues.generic, worker: 'test_worker' }
29-
).once
30-
31-
expect(prometheus).to have_received(:update_histogram_metric).with(
32-
:cc_job_duration_seconds,
33-
kind_of(Numeric),
34-
labels: { queue: VCAP::CloudController::Jobs::Queues.generic, worker: 'test_worker' }
35-
).once
36-
end
24+
allow(Time).to receive(:now).and_return(Time.now + 10.seconds)
25+
worker = Delayed::Worker.new
26+
worker.name = 'test_worker'
27+
worker.work_off(1)
28+
29+
expect(prometheus).to have_received(:update_histogram_metric).with(
30+
:cc_job_pickup_delay_seconds,
31+
be_within(0.5).of(10.0),
32+
labels: { queue: VCAP::CloudController::Jobs::Queues.generic, worker: 'test_worker' }
33+
).once
34+
35+
expect(prometheus).to have_received(:update_histogram_metric).with(
36+
:cc_job_duration_seconds,
37+
kind_of(Numeric),
38+
labels: { queue: VCAP::CloudController::Jobs::Queues.generic, worker: 'test_worker' }
39+
).once
3740
end
3841
end
3942
end

0 commit comments

Comments
 (0)