|
69 | 69 | describe '#start_working' do
|
70 | 70 | let(:cc_delayed_worker) { CloudController::DelayedWorker.new(options) }
|
71 | 71 |
|
| 72 | + before { allow(delayed_worker).to receive(:name).and_return(options[:name]) } |
| 73 | + |
72 | 74 | it 'sets up the environment and starts the worker' do
|
73 | 75 | expect(environment).to receive(:setup_environment).with(nil)
|
74 | 76 | expect(Delayed::Worker).to receive(:new).with(anything).and_return(delayed_worker)
|
|
86 | 88 | expect(Delayed::Worker.sleep_delay).to eq(5)
|
87 | 89 | end
|
88 | 90 |
|
| 91 | + it 'sets the worker name in the Steno context' do |
| 92 | + cc_delayed_worker.start_working |
| 93 | + expect(Steno.config.context.data[:worker_name]).to eq(options[:name]) |
| 94 | + end |
| 95 | + |
89 | 96 | context 'when the number of threads is specified' do
|
90 | 97 | before do
|
91 | 98 | allow(Delayed).to receive(:remove_const).with(:Worker)
|
92 | 99 | allow(Delayed).to receive(:const_set).with(:Worker, Delayed::ThreadedWorker)
|
| 100 | + allow(threaded_worker).to receive(:name) |
93 | 101 | options[:num_threads] = 7
|
94 | 102 | end
|
95 | 103 |
|
|
122 | 130 | expect(environment).to receive(:setup_environment).with(nil)
|
123 | 131 | expect(Delayed::Worker).to receive(:new).with(anything).and_return(delayed_worker).once
|
124 | 132 | expect(delayed_worker).to receive(:name=).with(options[:name]).once
|
125 |
| - expect(delayed_worker).to receive(:name).and_return(options[:name]).once |
| 133 | + expect(delayed_worker).to receive(:name).and_return(options[:name]).twice |
126 | 134 | expect(Delayed::Job).to receive(:clear_locks!).with(options[:name]).once
|
127 | 135 |
|
128 | 136 | cc_delayed_worker.clear_locks!
|
|
134 | 142 | expect(environment).to receive(:setup_environment).with(nil)
|
135 | 143 | expect(Delayed::Worker).to receive(:new).with(anything).and_return(threaded_worker).once
|
136 | 144 | expect(threaded_worker).to receive(:name=).with(options[:name]).once
|
137 |
| - expect(threaded_worker).to receive(:name).and_return(options[:name]).once |
| 145 | + expect(threaded_worker).to receive(:name).and_return(options[:name]).twice |
138 | 146 | expect(threaded_worker).to receive(:names_with_threads).and_return(["#{options[:name]} thread:1", "#{options[:name]} thread:2"]).once
|
139 | 147 | expect(Delayed::Job).to receive(:clear_locks!).with(options[:name]).once
|
140 | 148 | expect(Delayed::Job).to receive(:clear_locks!).with("#{options[:name]} thread:1").once
|
|
0 commit comments