roundhousekiq 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +4 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/Guardfile +44 -0
- data/LICENSE.txt +22 -0
- data/README.md +120 -0
- data/Rakefile +10 -0
- data/bin/roundhousekiq +17 -0
- data/chuck-norris.png +0 -0
- data/lib/roundhousekiq/configuration.rb +15 -0
- data/lib/roundhousekiq/runner.rb +103 -0
- data/lib/roundhousekiq/version.rb +3 -0
- data/lib/roundhousekiq/worker.rb +26 -0
- data/lib/roundhousekiq/worker_definition.rb +32 -0
- data/lib/roundhousekiq/workers.rb +42 -0
- data/lib/roundhousekiq.rb +19 -0
- data/roundhousekiq.gemspec +31 -0
- data/spec/fixtures/dummy_worker.rb +6 -0
- data/spec/roundhousekiq/configuration_spec.rb +17 -0
- data/spec/roundhousekiq/runner_spec.rb +350 -0
- data/spec/roundhousekiq/worker_definition_spec.rb +76 -0
- data/spec/roundhousekiq/worker_spec.rb +64 -0
- data/spec/roundhousekiq/workers_spec.rb +71 -0
- data/spec/roundhousekiq_spec.rb +34 -0
- data/spec/spec_helper.rb +84 -0
- metadata +207 -0
@@ -0,0 +1,350 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
require './spec/fixtures/dummy_worker'
|
3
|
+
|
4
|
+
describe Roundhousekiq::Runner do
|
5
|
+
|
6
|
+
# Method existence
|
7
|
+
it { should respond_to :connection }
|
8
|
+
it { should respond_to :channel }
|
9
|
+
it { should respond_to :queue }
|
10
|
+
it { should respond_to :consumer }
|
11
|
+
it { should respond_to :shutdown_runner }
|
12
|
+
it { should respond_to :exchange }
|
13
|
+
it { should respond_to :error_exchange }
|
14
|
+
it { should respond_to :queues }
|
15
|
+
it { should respond_to :queue_worker_map }
|
16
|
+
it { should respond_to :run }
|
17
|
+
|
18
|
+
describe 'constructor' do
|
19
|
+
it 'initializes queues with empty array' do
|
20
|
+
expect(subject.queues).to eq []
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'initializes queue_worker_map with empty hash' do
|
24
|
+
expect(subject.queue_worker_map).to eq({})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#run' do
|
29
|
+
before :each do
|
30
|
+
allow(subject).to receive(:establish_connection).and_return(nil)
|
31
|
+
allow(subject).to receive(:create_channel).and_return(nil)
|
32
|
+
allow(subject).to receive(:create_exchanges_and_queues).and_return(nil)
|
33
|
+
allow(subject).to receive(:setup_subscribers).and_return(nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'establishes an AMQP connection' do
|
37
|
+
expect(subject).to receive(:establish_connection)
|
38
|
+
subject.run
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'creates a channel' do
|
42
|
+
expect(subject).to receive(:create_channel)
|
43
|
+
subject.run
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'creates exchanges and queues' do
|
47
|
+
expect(subject).to receive(:create_exchanges_and_queues)
|
48
|
+
subject.run
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets up subscribers' do
|
52
|
+
expect(subject).to receive(:setup_subscribers)
|
53
|
+
subject.run
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#shutdown' do
|
58
|
+
before :each do
|
59
|
+
allow(subject).to receive(:sleep).and_return(nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'sets shutdown_runner to true' do
|
63
|
+
allow(Thread).to receive(:new).and_return(nil)
|
64
|
+
expect(subject.shutdown_runner).to be_falsy
|
65
|
+
subject.shutdown
|
66
|
+
expect(subject.shutdown_runner).to be true
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'closes the connection' do
|
70
|
+
subject.connection = double('connection')
|
71
|
+
|
72
|
+
allow(Thread).to receive(:new) do |&block|
|
73
|
+
expect(subject.connection).to receive(:try).with(:close)
|
74
|
+
block.call
|
75
|
+
end
|
76
|
+
|
77
|
+
subject.shutdown
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#shutdown?' do
|
82
|
+
it 'returns true if shutdown_runner is true' do
|
83
|
+
subject.shutdown_runner = true
|
84
|
+
expect(subject.shutdown?).to be true
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns false if shutdown_runner is false' do
|
88
|
+
subject.shutdown_runner = false
|
89
|
+
expect(subject.shutdown?).to be false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#establish_connection' do
|
94
|
+
before :each do
|
95
|
+
allow(Bunny).to receive(:new).and_return double('bunny', start: nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'creates a new Bunny instance' do
|
99
|
+
expect(Bunny).to receive(:new)
|
100
|
+
subject.establish_connection
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'passes connection settings on to Bunny' do
|
104
|
+
settings = subject.class.connection_settings
|
105
|
+
expect(Bunny).to receive(:new).with(settings, any_args)
|
106
|
+
subject.establish_connection
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'passes client properties on to Bunny' do
|
110
|
+
settings = subject.class.client_settings
|
111
|
+
expect(Bunny).to receive(:new).with(any_args, properties: settings)
|
112
|
+
subject.establish_connection
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'calls #start on the connection' do
|
116
|
+
bunny = double('bunny', start: nil)
|
117
|
+
allow(Bunny).to receive(:new).and_return bunny
|
118
|
+
expect(bunny).to receive(:start)
|
119
|
+
subject.establish_connection
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '.connection_settings' do
|
124
|
+
subject { Roundhousekiq::Runner }
|
125
|
+
|
126
|
+
it 'it requests the settings from Roundhousekiq' do
|
127
|
+
expect(Roundhousekiq).to receive(:config)
|
128
|
+
subject.connection_settings
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'it returns a hash' do
|
132
|
+
expect(subject.connection_settings).to be_instance_of Hash
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'it returns a hash with host, port, vhost, username and password' do
|
136
|
+
settings = subject.connection_settings
|
137
|
+
|
138
|
+
expect(settings).to have_key :host
|
139
|
+
expect(settings).to have_key :port
|
140
|
+
expect(settings).to have_key :vhost
|
141
|
+
expect(settings).to have_key :username
|
142
|
+
expect(settings).to have_key :password
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'returns the settings configured in Roundhousekiq' do
|
146
|
+
Roundhousekiq.configure do |config|
|
147
|
+
config.host = 'amqp-host'
|
148
|
+
config.port = 1234
|
149
|
+
config.vhost = 'rspec'
|
150
|
+
config.username = 'rspec_user'
|
151
|
+
config.password = 'very_secure'
|
152
|
+
end
|
153
|
+
|
154
|
+
settings = subject.connection_settings
|
155
|
+
expect(settings[:host]).to match 'amqp-host'
|
156
|
+
expect(settings[:port]).to match 1234
|
157
|
+
expect(settings[:vhost]).to match 'rspec'
|
158
|
+
expect(settings[:username]).to match 'rspec_user'
|
159
|
+
expect(settings[:password]).to match 'very_secure'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '.client_settings' do
|
164
|
+
subject { Roundhousekiq::Runner }
|
165
|
+
|
166
|
+
it 'takes the Bunny default settings' do
|
167
|
+
expect(Bunny::Session::DEFAULT_CLIENT_PROPERTIES).to receive(:merge)
|
168
|
+
subject.client_settings
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'returns a hash' do
|
172
|
+
expect(subject.client_settings).to be_instance_of Hash
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'sets the product name to "Roundhousekiq"' do
|
176
|
+
settings = subject.client_settings
|
177
|
+
expect(settings[:product]).to match 'Roundhousekiq'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe '#create_channel' do
|
182
|
+
it 'sets up a new channel' do
|
183
|
+
channel = double('channel', prefetch: nil)
|
184
|
+
subject.connection = double('connection', create_channel: channel)
|
185
|
+
subject.create_channel
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'sets the prefetch count to the value configured in config' do
|
189
|
+
config = double('config', prefetch: 512)
|
190
|
+
channel = double('channel', prefetch: nil)
|
191
|
+
subject.connection = double('connection', create_channel: channel)
|
192
|
+
expect(Roundhousekiq).to receive(:config).and_return config
|
193
|
+
expect(config).to receive(:prefetch)
|
194
|
+
expect(channel).to receive(:prefetch).with 512
|
195
|
+
subject.create_channel
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe '#create_exchanges_and_queues' do
|
200
|
+
let(:exchange) { double('exchange') }
|
201
|
+
let(:queue) { double('queue', bind: nil) }
|
202
|
+
let(:channel) { double('channel', exchange: exchange, queue: queue) }
|
203
|
+
let(:definition) do
|
204
|
+
definition = double 'definition'
|
205
|
+
allow(definition).to receive(:exchange).and_return({
|
206
|
+
name: 'exchange_name',
|
207
|
+
type: 'topic'
|
208
|
+
})
|
209
|
+
allow(definition).to receive(:queue).and_return({
|
210
|
+
name: 'queue_name',
|
211
|
+
durable: true,
|
212
|
+
auto_delete: false,
|
213
|
+
routing_key: 'routing_key'
|
214
|
+
})
|
215
|
+
definition
|
216
|
+
end
|
217
|
+
|
218
|
+
before :each do
|
219
|
+
subject.channel = channel
|
220
|
+
allow(Roundhousekiq::Workers).to receive(:definitions).and_return(
|
221
|
+
{ DummyWorker => definition }
|
222
|
+
)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'requests the worker definitions from Roundhousekiq::Workers' do
|
226
|
+
subject.create_exchanges_and_queues
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'creates the exchange for each worker' do
|
230
|
+
expect(channel).to receive(:exchange).with(
|
231
|
+
'exchange_name', type: 'topic', durable: true
|
232
|
+
)
|
233
|
+
subject.create_exchanges_and_queues
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'creates a queue for each worker' do
|
237
|
+
expect(channel).to receive(:queue).with(
|
238
|
+
'queue_name', auto_delete: false, durable: true
|
239
|
+
)
|
240
|
+
subject.create_exchanges_and_queues
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'sets up the binding for each worker' do
|
244
|
+
allow(channel).to receive(:queue).and_return queue
|
245
|
+
expect(queue).to receive(:bind).with exchange, routing_key: 'routing_key'
|
246
|
+
subject.create_exchanges_and_queues
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'saves the queue in queues' do
|
250
|
+
allow(queue).to receive(:bind).and_return queue
|
251
|
+
subject.create_exchanges_and_queues
|
252
|
+
expect(subject.queues.include? queue).to be true
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'adds each worker with the queue as key to the worker map' do
|
256
|
+
allow(queue).to receive(:bind).and_return queue
|
257
|
+
subject.create_exchanges_and_queues
|
258
|
+
expect(subject.queue_worker_map.keys.include? queue).to be true
|
259
|
+
expect(subject.queue_worker_map[queue]).to eq DummyWorker
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '#setup_subscribers' do
|
264
|
+
let(:queue) { double('queue', subscribe: nil) }
|
265
|
+
let(:channel) { double('channel', ack: nil) }
|
266
|
+
|
267
|
+
before :each do
|
268
|
+
allow(subject).to receive(:sleep).and_return(nil)
|
269
|
+
allow(subject).to receive(:shutdown?).and_return(true)
|
270
|
+
allow(subject).to receive(:process_message).and_return(nil)
|
271
|
+
allow(subject).to receive(:queues).and_return([queue])
|
272
|
+
allow(subject).to receive(:channel).and_return(channel)
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'sets up a subscription for each queue' do
|
276
|
+
expect(queue).to receive(:subscribe)
|
277
|
+
subject.setup_subscribers
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'configures manual ACK for the subscriptions' do
|
281
|
+
expect(queue).to receive(:subscribe).with(manual_ack: true)
|
282
|
+
subject.setup_subscribers
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'ACK each message once received' do
|
286
|
+
allow(queue).to receive(:subscribe) do |&block|
|
287
|
+
expect(subject.channel).to receive(:ack).with('amqp_tag')
|
288
|
+
|
289
|
+
block.call(
|
290
|
+
double('info', delivery_tag: 'amqp_tag'),
|
291
|
+
{},
|
292
|
+
"\{\}"
|
293
|
+
)
|
294
|
+
end
|
295
|
+
subject.setup_subscribers
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'passes the received message to #process_message' do
|
299
|
+
allow(channel).to receive(:ack).and_return(nil)
|
300
|
+
|
301
|
+
payload = JSON.dump('foo' => 'bar')
|
302
|
+
|
303
|
+
allow(queue).to receive(:subscribe) do |&block|
|
304
|
+
expect(subject).to receive(:process_message)
|
305
|
+
.with(queue, payload)
|
306
|
+
|
307
|
+
block.call(
|
308
|
+
double('info', delivery_tag: 'amqp_tag'),
|
309
|
+
{},
|
310
|
+
payload
|
311
|
+
)
|
312
|
+
end
|
313
|
+
subject.setup_subscribers
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'blocks in a loop until shutdown and just sleeps in between' do
|
317
|
+
allow(subject).to receive(:shutdown?).and_return(false, true)
|
318
|
+
|
319
|
+
expect(subject).to receive(:shutdown?).twice
|
320
|
+
expect(subject).to receive(:sleep).once
|
321
|
+
subject.setup_subscribers
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
describe '#process_message' do
|
326
|
+
let(:worker) { double('worker', perform_async: nil) }
|
327
|
+
|
328
|
+
it 'fetches the corresponding worker' do
|
329
|
+
expect(subject.queue_worker_map).to receive(:[]).with('queue')
|
330
|
+
.and_return(worker)
|
331
|
+
subject.process_message 'queue', "\{\}"
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'schedules the worker' do
|
335
|
+
allow(subject.queue_worker_map).to receive(:[]).with('queue')
|
336
|
+
.and_return(worker)
|
337
|
+
expect(worker).to receive(:perform_async)
|
338
|
+
subject.process_message 'queue', "\{\}"
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'parses the message payload and passes it to the worker' do
|
342
|
+
allow(subject.queue_worker_map).to receive(:[]).with('queue')
|
343
|
+
.and_return(worker)
|
344
|
+
|
345
|
+
payload = { 'foo' => 'bar' }
|
346
|
+
expect(worker).to receive(:perform_async).with payload
|
347
|
+
subject.process_message 'queue', JSON.dump(payload)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
describe Roundhousekiq::WorkerDefinition do
|
2
|
+
let(:definition) { Roundhousekiq::WorkerDefinition.new }
|
3
|
+
|
4
|
+
# Method existence
|
5
|
+
it { should respond_to :exchange }
|
6
|
+
it { should respond_to :queue }
|
7
|
+
it { should respond_to :exchange_name= }
|
8
|
+
it { should respond_to :exchange_type= }
|
9
|
+
it { should respond_to :queue_name= }
|
10
|
+
it { should respond_to :routing_key= }
|
11
|
+
|
12
|
+
describe '#exchange' do
|
13
|
+
it 'returns a hash' do
|
14
|
+
expect(definition.exchange).to be_instance_of Hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_name' do
|
19
|
+
it 'sets the name key in exchange' do
|
20
|
+
expect(definition.exchange[:name]).to be_nil
|
21
|
+
definition.exchange_name = 'rspec'
|
22
|
+
expect(definition.exchange[:name]).to match('rspec')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#exchange_type' do
|
27
|
+
it 'sets the type key in exchange' do
|
28
|
+
expect(definition.exchange[:type]).to be_nil
|
29
|
+
definition.exchange_type = 'topic'
|
30
|
+
expect(definition.exchange[:type]).to match('topic')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#queue_name' do
|
35
|
+
it 'sets the name in queue hash' do
|
36
|
+
expect(definition.queue[:name]).to be_nil
|
37
|
+
definition.queue_name = 'queue'
|
38
|
+
expect(definition.queue[:name]).to match('queue')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'defaults the queue name to empty string' do
|
42
|
+
expect(definition.queue[:name]).to be_nil
|
43
|
+
definition.queue_name = nil
|
44
|
+
expect(definition.queue[:name]).to match('')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'defines queue as durable for a named queue' do
|
48
|
+
definition.queue_name = 'named_queue'
|
49
|
+
expect(definition.queue[:durable]).to be true
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'defines queue as non-durable for auto-generated queues' do
|
53
|
+
definition.queue_name = nil
|
54
|
+
expect(definition.queue[:durable]).to be false
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'does not mark queue for auto-delete for a named queue' do
|
58
|
+
definition.queue_name = 'named_queue'
|
59
|
+
expect(definition.queue[:auto_delete]).to be false
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'marks queue for auto-delete for auto-generated queues' do
|
63
|
+
definition.queue_name = nil
|
64
|
+
expect(definition.queue[:auto_delete]).to be true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#routing_key' do
|
69
|
+
it 'sets the routing key in queue' do
|
70
|
+
expect(definition.queue[:routing_key]).to be_nil
|
71
|
+
definition.routing_key = 'routeMe'
|
72
|
+
expect(definition.queue[:routing_key]).to match('routeMe')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require './spec/fixtures/dummy_worker'
|
2
|
+
|
3
|
+
describe Roundhousekiq::Worker do
|
4
|
+
|
5
|
+
# Method existence
|
6
|
+
it { should respond_to :included }
|
7
|
+
|
8
|
+
describe '.included' do
|
9
|
+
it 'extends the class methods module' do
|
10
|
+
worker = double('worker')
|
11
|
+
expect(worker).to receive(:extend)
|
12
|
+
.with(Roundhousekiq::Worker::ClassMethods)
|
13
|
+
Roundhousekiq::Worker.send :included, worker
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'registers the worker' do
|
17
|
+
worker = double('worker')
|
18
|
+
expect(Roundhousekiq::Workers).to receive(:register).with(worker)
|
19
|
+
Roundhousekiq::Worker.send :included, worker
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '::ClassMethods' do
|
24
|
+
subject { DummyWorker }
|
25
|
+
|
26
|
+
it { should respond_to :exchange_name }
|
27
|
+
it { should respond_to :exchange_type }
|
28
|
+
it { should respond_to :queue_name }
|
29
|
+
it { should respond_to :routing_key }
|
30
|
+
|
31
|
+
describe '.exchange_name' do
|
32
|
+
it 'calls Roundhousekiq::Workers#exchange_name_for' do
|
33
|
+
expect(Roundhousekiq::Workers).to receive(:exchange_name_for)
|
34
|
+
.with(subject, 'notifications')
|
35
|
+
subject.exchange_name 'notifications'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.exchange_type' do
|
40
|
+
it 'calls Roundhousekiq::Workers#exchange_type_for' do
|
41
|
+
expect(Roundhousekiq::Workers).to receive(:exchange_type_for)
|
42
|
+
.with(subject, 'topic')
|
43
|
+
subject.exchange_type 'topic'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.queue_name' do
|
48
|
+
it 'calls Roundhousekiq::Workers#queue_name_for' do
|
49
|
+
expect(Roundhousekiq::Workers).to receive(:queue_name_for)
|
50
|
+
.with(subject, 'queue')
|
51
|
+
subject.queue_name 'queue'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '.routing_key' do
|
56
|
+
it 'calls Roundhousekiq::Workers#routing_key_for' do
|
57
|
+
expect(Roundhousekiq::Workers).to receive(:routing_key_for)
|
58
|
+
.with(subject, 'key.*')
|
59
|
+
subject.routing_key 'key.*'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require './spec/fixtures/dummy_worker'
|
2
|
+
|
3
|
+
describe Roundhousekiq::Workers do
|
4
|
+
subject { Roundhousekiq::Workers }
|
5
|
+
|
6
|
+
# Methods
|
7
|
+
it { should respond_to :register }
|
8
|
+
it { should respond_to :definitions }
|
9
|
+
it { should respond_to :exchange_name_for }
|
10
|
+
it { should respond_to :exchange_type_for }
|
11
|
+
it { should respond_to :queue_name_for }
|
12
|
+
it { should respond_to :routing_key_for }
|
13
|
+
|
14
|
+
describe '.register' do
|
15
|
+
it 'creates a new definition for the given class' do
|
16
|
+
Roundhousekiq::Workers.register DummyWorker
|
17
|
+
definitions = Roundhousekiq::Workers.definitions
|
18
|
+
expect(definitions).to have_key DummyWorker
|
19
|
+
expect(definitions[DummyWorker]).to be_instance_of(
|
20
|
+
Roundhousekiq::WorkerDefinition
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.definitions' do
|
26
|
+
it 'returns the internal definitions hash' do
|
27
|
+
definitions = Roundhousekiq::Workers.class_variable_get '@@definitions'
|
28
|
+
expect(Roundhousekiq::Workers.definitions).to eq definitions
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.exchange_name_for' do
|
33
|
+
it 'passes the exchange name to the workers definition' do
|
34
|
+
worker = double('worker')
|
35
|
+
Roundhousekiq::Workers.register worker
|
36
|
+
definition = Roundhousekiq::Workers.definitions[worker]
|
37
|
+
expect(definition).to receive(:exchange_name=).with 'notifications'
|
38
|
+
subject.exchange_name_for worker, 'notifications'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.exchange_type_for' do
|
43
|
+
it 'passes the exchange type to the workers definition' do
|
44
|
+
worker = double('worker')
|
45
|
+
Roundhousekiq::Workers.register worker
|
46
|
+
definition = Roundhousekiq::Workers.definitions[worker]
|
47
|
+
expect(definition).to receive(:exchange_type=).with 'topic'
|
48
|
+
subject.exchange_type_for worker, 'topic'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.queue_name_for' do
|
53
|
+
it 'passes the queue name to the workers definition' do
|
54
|
+
worker = double('worker')
|
55
|
+
Roundhousekiq::Workers.register worker
|
56
|
+
definition = Roundhousekiq::Workers.definitions[worker]
|
57
|
+
expect(definition).to receive(:queue_name=).with 'importantQueue'
|
58
|
+
subject.queue_name_for worker, 'importantQueue'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.routing_key_for' do
|
63
|
+
it 'passes the routing key to the workers definition' do
|
64
|
+
worker = double('worker')
|
65
|
+
Roundhousekiq::Workers.register worker
|
66
|
+
definition = Roundhousekiq::Workers.definitions[worker]
|
67
|
+
expect(definition).to receive(:routing_key=).with 'notifications.*'
|
68
|
+
subject.routing_key_for worker, 'notifications.*'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
describe Roundhousekiq do
|
2
|
+
|
3
|
+
# Method existence
|
4
|
+
it { should respond_to :config }
|
5
|
+
it { should respond_to :configure }
|
6
|
+
|
7
|
+
describe '.config' do
|
8
|
+
it 'returns a Configuration' do
|
9
|
+
expect(Roundhousekiq.config).to be_instance_of Roundhousekiq::Configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'always returns the same configuration' do
|
13
|
+
config = Roundhousekiq.config
|
14
|
+
expect(Roundhousekiq.config).to eq config
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.configure' do
|
19
|
+
it 'passes the Gem configuration to a block' do
|
20
|
+
Roundhousekiq.configure do |config|
|
21
|
+
expect(config).to be_instance_of Roundhousekiq::Configuration
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'stores the configuration' do
|
26
|
+
configuration = nil
|
27
|
+
Roundhousekiq.configure do |config|
|
28
|
+
configuration = config
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(Roundhousekiq.instance_variable_get '@config').to eq configuration
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Load Code Climate coverage reporter
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
|
5
|
+
require './lib/roundhousekiq'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
# rspec-expectations config goes here. You can use an alternate
|
9
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
10
|
+
# assertions if you prefer.
|
11
|
+
config.expect_with :rspec do |expectations|
|
12
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
13
|
+
# and `failure_message` of custom matchers include text for helper methods
|
14
|
+
# defined using `chain`, e.g.:
|
15
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
16
|
+
# # => "be bigger than 2 and smaller than 4"
|
17
|
+
# ...rather than:
|
18
|
+
# # => "be bigger than 2"
|
19
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
20
|
+
end
|
21
|
+
|
22
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
23
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
24
|
+
config.mock_with :rspec do |mocks|
|
25
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
26
|
+
# a real object. This is generally recommended, and will default to
|
27
|
+
# `true` in RSpec 4.
|
28
|
+
mocks.verify_partial_doubles = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# The settings below are suggested to provide a good initial experience
|
32
|
+
# with RSpec, but feel free to customize to your heart's content.
|
33
|
+
=begin
|
34
|
+
# These two settings work together to allow you to limit a spec run
|
35
|
+
# to individual examples or groups you care about by tagging them with
|
36
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
37
|
+
# get run.
|
38
|
+
config.filter_run :focus
|
39
|
+
config.run_all_when_everything_filtered = true
|
40
|
+
|
41
|
+
# Allows RSpec to persist some state between runs in order to support
|
42
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
43
|
+
# you configure your source control system to ignore this file.
|
44
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
45
|
+
|
46
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
47
|
+
# recommended. For more details, see:
|
48
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
49
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
50
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
51
|
+
config.disable_monkey_patching!
|
52
|
+
|
53
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
54
|
+
# be too noisy due to issues in dependencies.
|
55
|
+
config.warnings = true
|
56
|
+
|
57
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
58
|
+
# file, and it's useful to allow more verbose output when running an
|
59
|
+
# individual spec file.
|
60
|
+
if config.files_to_run.one?
|
61
|
+
# Use the documentation formatter for detailed output,
|
62
|
+
# unless a formatter has already been configured
|
63
|
+
# (e.g. via a command-line flag).
|
64
|
+
config.default_formatter = 'doc'
|
65
|
+
end
|
66
|
+
|
67
|
+
# Print the 10 slowest examples and example groups at the
|
68
|
+
# end of the spec run, to help surface which specs are running
|
69
|
+
# particularly slow.
|
70
|
+
config.profile_examples = 10
|
71
|
+
|
72
|
+
# Run specs in random order to surface order dependencies. If you find an
|
73
|
+
# order dependency and want to debug it, you can fix the order by providing
|
74
|
+
# the seed, which is printed after each run.
|
75
|
+
# --seed 1234
|
76
|
+
config.order = :random
|
77
|
+
|
78
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
79
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
80
|
+
# test failures related to randomization by passing the same `--seed` value
|
81
|
+
# as the one that triggered the failure.
|
82
|
+
Kernel.srand config.seed
|
83
|
+
=end
|
84
|
+
end
|