|
3 | 3 | require 'spec_helper' |
4 | 4 |
|
5 | 5 | RSpec.describe Minigun::Worker do |
| 6 | + let(:stage_registry) { instance_double(Minigun::StageRegistry, register: nil) } |
| 7 | + let(:task) { instance_double(Minigun::Task, find_queue: nil, stage_registry: stage_registry) } |
| 8 | + |
6 | 9 | let(:pipeline) do |
7 | 10 | instance_double( |
8 | 11 | Minigun::Pipeline, |
9 | 12 | name: 'test_pipeline', |
10 | 13 | dag: dag, |
11 | | - stage_input_queues: {}, |
| 14 | + task: task, |
12 | 15 | runtime_edges: {}, |
13 | 16 | context: user_context, |
14 | 17 | stats: stats, |
|
22 | 25 | name: :test_stage, |
23 | 26 | execution_context: nil, |
24 | 27 | log_type: 'Worker', |
25 | | - run_mode: :streaming |
| 28 | + run_mode: :streaming, |
| 29 | + task: task |
26 | 30 | ) |
27 | 31 | end |
28 | 32 |
|
|
55 | 59 | describe '#start' do |
56 | 60 | it 'starts a worker thread' do |
57 | 61 | input_queue = Queue.new |
58 | | - allow(pipeline).to receive(:stage_input_queues) |
59 | | - .and_return({ test_stage: input_queue }) |
| 62 | + allow(task).to receive(:find_queue).with(stage).and_return(input_queue) |
60 | 63 | allow(dag).to receive(:upstream).with(:test_stage).and_return([:upstream]) |
61 | 64 | allow(dag).to receive(:downstream).with(:test_stage).and_return([]) |
62 | 65 |
|
|
89 | 92 | describe '#join' do |
90 | 93 | it 'waits for worker thread to complete' do |
91 | 94 | input_queue = Queue.new |
92 | | - allow(pipeline).to receive(:stage_input_queues) |
93 | | - .and_return({ test_stage: input_queue }) |
| 95 | + allow(task).to receive(:find_queue).with(stage).and_return(input_queue) |
94 | 96 |
|
95 | 97 | worker = described_class.new(pipeline, stage, config) |
96 | 98 |
|
|
151 | 153 |
|
152 | 154 | describe 'disconnected stage handling' do |
153 | 155 | it 'exits early if no upstream sources' do |
154 | | - allow(pipeline).to receive(:stage_input_queues) |
155 | | - .and_return({ test_stage: Queue.new }) |
156 | | - allow(dag).to receive(:upstream).with(:test_stage).and_return([]) |
157 | | - allow(dag).to receive(:downstream).with(:test_stage).and_return([]) |
| 156 | + input_queue = Queue.new |
| 157 | + allow(task).to receive(:find_queue).with(stage).and_return(input_queue) |
| 158 | + allow(dag).to receive(:upstream).with(stage).and_return([]) |
| 159 | + allow(dag).to receive(:downstream).with(stage).and_return([]) |
158 | 160 |
|
159 | 161 | worker = described_class.new(pipeline, stage, config) |
160 | 162 |
|
|
167 | 169 | end |
168 | 170 |
|
169 | 171 | it 'sends END signals to downstream if disconnected' do |
170 | | - allow(pipeline).to receive(:stage_input_queues) |
171 | | - .and_return({ test_stage: Queue.new, downstream: Queue.new }) |
172 | | - allow(dag).to receive(:upstream).with(:test_stage).and_return([]) |
173 | | - allow(dag).to receive(:downstream).with(:test_stage).and_return([:downstream]) |
174 | | - |
| 172 | + input_queue = Queue.new |
| 173 | + downstream_stage = double('downstream_stage', name: :downstream, task: task) |
175 | 174 | downstream_queue = Queue.new |
176 | | - allow(pipeline).to receive(:stage_input_queues) |
177 | | - .and_return({ test_stage: Queue.new, downstream: downstream_queue }) |
| 175 | + |
| 176 | + allow(task).to receive(:find_queue).with(stage).and_return(input_queue) |
| 177 | + allow(task).to receive(:find_queue).with(downstream_stage).and_return(downstream_queue) |
| 178 | + allow(dag).to receive(:upstream).with(stage).and_return([]) |
| 179 | + allow(dag).to receive(:downstream).with(stage).and_return([downstream_stage]) |
178 | 180 |
|
179 | 181 | worker = described_class.new(pipeline, stage, config) |
180 | 182 | worker.start |
|
213 | 215 | target_a_queue = Queue.new |
214 | 216 | target_b_queue = Queue.new |
215 | 217 |
|
216 | | - allow(pipeline).to receive(:stage_input_queues) |
217 | | - .and_return({ broadcast_router => input_queue, target_a_stage => target_a_queue, target_b_stage => target_b_queue }) |
| 218 | + allow(task).to receive(:find_queue).with(broadcast_router).and_return(input_queue) |
| 219 | + allow(task).to receive(:find_queue).with(target_a_stage).and_return(target_a_queue) |
| 220 | + allow(task).to receive(:find_queue).with(target_b_stage).and_return(target_b_queue) |
218 | 221 | allow(dag).to receive(:upstream).with(broadcast_router).and_return([source_stage]) |
219 | 222 |
|
220 | 223 | # Put items and END signal |
|
261 | 264 | describe 'logging' do |
262 | 265 | it 'logs when starting' do |
263 | 266 | input_queue = Queue.new |
264 | | - allow(pipeline).to receive(:stage_input_queues) |
265 | | - .and_return({ test_stage: input_queue }) |
| 267 | + allow(task).to receive(:find_queue).with(stage).and_return(input_queue) |
266 | 268 |
|
267 | 269 | input_queue << Minigun::EndOfSource.new(:upstream) |
268 | 270 |
|
|
277 | 279 |
|
278 | 280 | it 'logs when done' do |
279 | 281 | input_queue = Queue.new |
280 | | - allow(pipeline).to receive(:stage_input_queues) |
281 | | - .and_return({ test_stage: input_queue }) |
| 282 | + allow(task).to receive(:find_queue).with(stage).and_return(input_queue) |
282 | 283 | allow(dag).to receive(:upstream).with(:test_stage).and_return([:upstream]) |
283 | 284 | allow(dag).to receive(:downstream).with(:test_stage).and_return([]) |
284 | 285 |
|
|
0 commit comments