File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
spec/unit/lib/delayed_job_plugins Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 11module DelayedJobMetrics
22 class Plugin < Delayed ::Plugin
3- def self . prometheus
4- @prometheus ||= CloudController ::DependencyLocator . instance . cc_worker_prometheus_updater
3+ class << self
4+ attr_writer :prometheus
5+
6+ def prometheus
7+ @prometheus ||= CloudController ::DependencyLocator . instance . cc_worker_prometheus_updater
8+ end
59 end
610
711 callbacks do |lifecycle |
Original file line number Diff line number Diff line change 11require 'spec_helper'
22
33RSpec . describe DelayedJobMetrics ::Plugin do
4- let ( :worker ) { instance_double ( Delayed :: Worker , name : 'test_worker' ) }
4+ let ( :prometheus ) { instance_double ( VCAP :: CloudController :: Metrics :: PrometheusUpdater ) }
55
66 before do
7- @prometheus = instance_double ( VCAP ::CloudController ::Metrics ::PrometheusUpdater )
8- allow ( CloudController ::DependencyLocator . instance ) . to receive ( :cc_worker_prometheus_updater ) . and_return ( @prometheus )
9- allow ( @prometheus ) . to receive ( :update_histogram_metric )
7+ DelayedJobMetrics ::Plugin . prometheus = prometheus
8+ allow ( prometheus ) . to receive ( :update_histogram_metric )
9+ end
10+
11+ after do
12+ DelayedJobMetrics ::Plugin . prometheus = nil # Reset after each test
1013 end
1114
1215 it 'loads the plugin' do
2629 worker . name = 'test_worker'
2730 worker . work_off ( 1 )
2831
29- expect ( @ prometheus) . to have_received ( :update_histogram_metric ) . with (
32+ expect ( prometheus ) . to have_received ( :update_histogram_metric ) . with (
3033 :cc_job_pickup_delay_seconds ,
3134 be_within ( 0.5 ) . of ( 10.0 ) ,
3235 labels : { queue : VCAP ::CloudController ::Jobs ::Queues . generic , worker : 'test_worker' }
3336 ) . once
3437
35- expect ( @ prometheus) . to have_received ( :update_histogram_metric ) . with (
38+ expect ( prometheus ) . to have_received ( :update_histogram_metric ) . with (
3639 :cc_job_duration_seconds ,
3740 kind_of ( Numeric ) ,
3841 labels : { queue : VCAP ::CloudController ::Jobs ::Queues . generic , worker : 'test_worker' }
You can’t perform that action at this time.
0 commit comments