sidekiq-bus 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/sidekiq_bus/adapter.rb +1 -1
- data/lib/sidekiq_bus/middleware/retry.rb +10 -10
- data/lib/sidekiq_bus/tasks.rb +4 -4
- data/lib/sidekiq_bus/version.rb +3 -1
- data/spec/adapter/integration_spec.rb +45 -45
- data/spec/adapter/support.rb +2 -0
- data/spec/adapter_spec.rb +2 -1
- data/spec/application_spec.rb +97 -97
- data/spec/config_spec.rb +26 -29
- data/spec/dispatch_spec.rb +39 -40
- data/spec/driver_spec.rb +60 -58
- data/spec/heartbeat_spec.rb +26 -24
- data/spec/integration_spec.rb +41 -40
- data/spec/matcher_spec.rb +104 -102
- data/spec/publish_spec.rb +46 -46
- data/spec/publisher_spec.rb +3 -1
- data/spec/rider_spec.rb +16 -14
- data/spec/spec_helper.rb +9 -8
- data/spec/subscriber_spec.rb +227 -227
- data/spec/subscription_list_spec.rb +29 -29
- data/spec/subscription_spec.rb +37 -36
- data/spec/worker_spec.rb +13 -11
- metadata +2 -2
@@ -1,43 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe SubscriptionList do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
mult = {
|
8
|
-
|
7
|
+
describe '.from_redis' do
|
8
|
+
it 'should return from attributes' do
|
9
|
+
mult = { 'event_one' => { 'class' => 'MyClass', 'queue_name' => 'default', 'key' => 'event_one', 'matcher' => { 'bus_event_type' => 'event_one' } },
|
10
|
+
'event_two' => { 'class' => 'MyClass', 'queue_name' => 'else', 'key' => 'event_two', 'matcher' => { 'bus_event_type' => 'event_two' } } }
|
9
11
|
|
10
12
|
list = SubscriptionList.from_redis(mult)
|
11
13
|
expect(list.size).to eq(2)
|
12
|
-
one = list.key(
|
13
|
-
two = list.key(
|
14
|
-
|
15
|
-
expect(one.key).to eq(
|
16
|
-
expect(one.key).to eq(
|
17
|
-
expect(one.queue_name).to eq(
|
18
|
-
expect(one.class_name).to eq(
|
19
|
-
expect(one.matcher.filters).to eq(
|
20
|
-
|
21
|
-
expect(two.key).to eq(
|
22
|
-
expect(two.key).to eq(
|
23
|
-
expect(two.queue_name).to eq(
|
24
|
-
expect(two.class_name).to eq(
|
25
|
-
expect(two.matcher.filters).to eq(
|
14
|
+
one = list.key('event_one')
|
15
|
+
two = list.key('event_two')
|
16
|
+
|
17
|
+
expect(one.key).to eq('event_one')
|
18
|
+
expect(one.key).to eq('event_one')
|
19
|
+
expect(one.queue_name).to eq('default')
|
20
|
+
expect(one.class_name).to eq('MyClass')
|
21
|
+
expect(one.matcher.filters).to eq('bus_event_type' => 'event_one')
|
22
|
+
|
23
|
+
expect(two.key).to eq('event_two')
|
24
|
+
expect(two.key).to eq('event_two')
|
25
|
+
expect(two.queue_name).to eq('else')
|
26
|
+
expect(two.class_name).to eq('MyClass')
|
27
|
+
expect(two.matcher.filters).to eq('bus_event_type' => 'event_two')
|
26
28
|
end
|
27
29
|
end
|
28
|
-
|
29
|
-
describe
|
30
|
-
it
|
30
|
+
|
31
|
+
describe '#to_redis' do
|
32
|
+
it 'should generate what to store' do
|
31
33
|
list = SubscriptionList.new
|
32
|
-
list.add(Subscription.new(
|
33
|
-
list.add(Subscription.new(
|
34
|
-
|
34
|
+
list.add(Subscription.new('default', 'key1', 'MyClass', 'bus_event_type' => 'event_one'))
|
35
|
+
list.add(Subscription.new('else_ok', 'key2', 'MyClass', 'bus_event_type' => 'event_two'))
|
36
|
+
|
35
37
|
hash = list.to_redis
|
36
|
-
expect(hash).to eq(
|
37
|
-
|
38
|
-
})
|
39
|
-
|
38
|
+
expect(hash).to eq('key1' => { 'queue_name' => 'default', 'key' => 'key1', 'class' => 'MyClass', 'matcher' => { 'bus_event_type' => 'event_one' } },
|
39
|
+
'key2' => { 'queue_name' => 'else_ok', 'key' => 'key2', 'class' => 'MyClass', 'matcher' => { 'bus_event_type' => 'event_two' } })
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
data/spec/subscription_spec.rb
CHANGED
@@ -1,53 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe Subscription do
|
5
|
-
it
|
6
|
-
expect(Subscription.new(
|
7
|
-
expect(Subscription.new(
|
8
|
-
expect(Subscription.new(
|
7
|
+
it 'should normalize the queue name' do
|
8
|
+
expect(Subscription.new('test', 'my_event', 'MyClass', {}, nil).queue_name).to eq('test')
|
9
|
+
expect(Subscription.new('tes t', 'my_event', 'MyClass', {}, nil).queue_name).to eq('tes_t')
|
10
|
+
expect(Subscription.new('t%s', 'my_event', 'MyClass', {}, nil).queue_name).to eq('t_s')
|
9
11
|
end
|
10
|
-
|
11
|
-
describe
|
12
|
-
it
|
13
|
-
executor =
|
14
|
-
sub = Subscription.register(
|
12
|
+
|
13
|
+
describe '.register' do
|
14
|
+
it 'should take in args from dispatcher' do
|
15
|
+
executor = proc { |attributes| }
|
16
|
+
sub = Subscription.register('queue_name', 'mykey', 'MyClass', { 'bus_event_type' => 'my_event' }, executor)
|
15
17
|
expect(sub.send(:executor)).to eq(executor)
|
16
|
-
expect(sub.matcher.filters).to eq(
|
17
|
-
expect(sub.queue_name).to eq(
|
18
|
-
expect(sub.key).to eq(
|
19
|
-
expect(sub.class_name).to eq(
|
18
|
+
expect(sub.matcher.filters).to eq('bus_event_type' => 'my_event')
|
19
|
+
expect(sub.queue_name).to eq('queue_name')
|
20
|
+
expect(sub.key).to eq('mykey')
|
21
|
+
expect(sub.class_name).to eq('MyClass')
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
23
|
-
describe
|
24
|
-
it
|
24
|
+
|
25
|
+
describe '#execute!' do
|
26
|
+
it 'should call the executor with the attributes' do
|
25
27
|
exec = Object.new
|
26
28
|
expect(exec).to receive(:call)
|
27
|
-
|
28
|
-
sub = Subscription.new(
|
29
|
-
sub.execute!(
|
29
|
+
|
30
|
+
sub = Subscription.new('x', 'y', 'ClassName', {}, exec)
|
31
|
+
sub.execute!('ok' => true)
|
30
32
|
end
|
31
33
|
end
|
32
|
-
|
33
|
-
describe
|
34
|
-
it
|
35
|
-
sub = Subscription.new(
|
36
|
-
expect(sub.to_redis).to eq(
|
34
|
+
|
35
|
+
describe '#to_redis' do
|
36
|
+
it 'should return what to store for this subscription' do
|
37
|
+
sub = Subscription.new('queue_one', 'xyz', 'ClassName', { 'bus_event_type' => 'my_event' }, nil)
|
38
|
+
expect(sub.to_redis).to eq('queue_name' => 'queue_one', 'key' => 'xyz', 'class' => 'ClassName', 'matcher' => { 'bus_event_type' => 'my_event' })
|
37
39
|
end
|
38
40
|
end
|
39
|
-
|
40
|
-
describe
|
41
|
-
it
|
42
|
-
expect(Subscription.new(
|
43
|
-
expect(Subscription.new(
|
44
|
-
expect(Subscription.new(
|
45
|
-
expect(Subscription.new(
|
46
|
-
expect(Subscription.new(
|
47
|
-
expect(Subscription.new(
|
48
|
-
expect(Subscription.new(
|
41
|
+
|
42
|
+
describe '#matches?' do
|
43
|
+
it 'should do pattern stuff' do
|
44
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one').matches?('bus_event_type' => 'one')).to eq(true)
|
45
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one').matches?('bus_event_type' => 'onex')).to eq(false)
|
46
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => '^one.*$').matches?('bus_event_type' => 'onex')).to eq(true)
|
47
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one.*').matches?('bus_event_type' => 'onex')).to eq(true)
|
48
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one.?').matches?('bus_event_type' => 'onex')).to eq(true)
|
49
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one.?').matches?('bus_event_type' => 'one')).to eq(true)
|
50
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => '\\').matches?('bus_event_type' => 'one')).to eq(false)
|
49
51
|
end
|
50
52
|
end
|
51
|
-
|
52
53
|
end
|
53
|
-
end
|
54
|
+
end
|
data/spec/worker_spec.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe Worker do
|
5
|
-
it
|
6
|
-
hash = {
|
7
|
+
it 'should proxy to given class' do
|
8
|
+
hash = { 'bus_class_proxy' => 'QueueBus::Driver', 'ok' => true }
|
7
9
|
expect(QueueBus::Driver).to receive(:perform).with(hash)
|
8
10
|
QueueBus::Worker.perform(JSON.generate(hash))
|
9
11
|
end
|
10
12
|
|
11
|
-
it
|
12
|
-
hash = {
|
13
|
+
it 'should use instance' do
|
14
|
+
hash = { 'bus_class_proxy' => 'QueueBus::Rider', 'ok' => true }
|
13
15
|
expect(QueueBus::Rider).to receive(:perform).with(hash)
|
14
16
|
QueueBus::Worker.new.perform(JSON.generate(hash))
|
15
17
|
end
|
16
18
|
|
17
|
-
it
|
18
|
-
hash = {
|
19
|
+
it 'should not freak out if class not there anymore' do
|
20
|
+
hash = { 'bus_class_proxy' => 'QueueBus::BadClass', 'ok' => true }
|
19
21
|
|
20
22
|
expect(QueueBus::Worker.perform(JSON.generate(hash))).to eq(nil)
|
21
23
|
end
|
22
24
|
|
23
|
-
it
|
24
|
-
hash = {
|
25
|
-
expect(QueueBus::Rider).to receive(:perform).with(hash).and_raise(
|
26
|
-
expect
|
25
|
+
it 'should raise error if proxy raises error' do
|
26
|
+
hash = { 'bus_class_proxy' => 'QueueBus::Rider', 'ok' => true }
|
27
|
+
expect(QueueBus::Rider).to receive(:perform).with(hash).and_raise('rider crash')
|
28
|
+
expect do
|
27
29
|
QueueBus::Worker.perform(JSON.generate(hash))
|
28
|
-
|
30
|
+
end.to raise_error('rider crash')
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Leonard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: queue-bus
|