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
data/spec/integration_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
|
-
describe
|
5
|
-
it
|
6
|
-
write1 = Subscription.new(
|
7
|
-
write2 = Subscription.new(
|
8
|
-
|
9
|
-
expect(write1.matches?(
|
10
|
-
expect(write1.matches?(
|
11
|
-
expect(write1.matches?(
|
12
|
-
|
13
|
-
expect(write2.matches?(
|
14
|
-
expect(write2.matches?(
|
15
|
-
expect(write2.matches?(
|
16
|
-
expect(write2.matches?(
|
17
|
-
expect(write2.matches?(
|
18
|
-
|
6
|
+
describe 'Integration' do
|
7
|
+
it 'should round trip attributes' do
|
8
|
+
write1 = Subscription.new('default', 'key1', 'MyClass1', 'bus_event_type' => 'event_one')
|
9
|
+
write2 = Subscription.new('else_ok', 'key2', 'MyClass2', 'bus_event_type' => /^[ab]here/) # regex
|
10
|
+
|
11
|
+
expect(write1.matches?('bus_event_type' => 'event_one')).to eq(true)
|
12
|
+
expect(write1.matches?('bus_event_type' => 'event_one1')).to eq(false)
|
13
|
+
expect(write1.matches?('bus_event_type' => 'aevent_one')).to eq(false)
|
14
|
+
|
15
|
+
expect(write2.matches?('bus_event_type' => 'ahere')).to eq(true)
|
16
|
+
expect(write2.matches?('bus_event_type' => 'bhere')).to eq(true)
|
17
|
+
expect(write2.matches?('bus_event_type' => 'qhere')).to eq(false)
|
18
|
+
expect(write2.matches?('bus_event_type' => 'abhere')).to eq(false)
|
19
|
+
expect(write2.matches?('bus_event_type' => '[ab]here')).to eq(false)
|
20
|
+
|
19
21
|
write = SubscriptionList.new
|
20
22
|
write.add(write1)
|
21
23
|
write.add(write2)
|
22
|
-
|
23
|
-
app = Application.new(
|
24
|
+
|
25
|
+
app = Application.new('test')
|
24
26
|
app.subscribe(write)
|
25
|
-
|
26
|
-
reset_test_adapter
|
27
|
-
app = Application.new(
|
27
|
+
|
28
|
+
reset_test_adapter # reset to make sure we read from redis
|
29
|
+
app = Application.new('test')
|
28
30
|
read = app.send(:subscriptions)
|
29
|
-
|
31
|
+
|
30
32
|
expect(read.size).to eq(2)
|
31
|
-
read1 = read.key(
|
32
|
-
read2 = read.key(
|
33
|
+
read1 = read.key('key1')
|
34
|
+
read2 = read.key('key2')
|
33
35
|
expect(read1).not_to be_nil
|
34
36
|
expect(read2).not_to be_nil
|
35
|
-
|
36
|
-
expect(read1.queue_name).to eq(
|
37
|
-
expect(read1.class_name).to eq(
|
38
|
-
expect(read2.queue_name).to eq(
|
39
|
-
expect(read2.class_name).to eq(
|
40
|
-
|
41
|
-
expect(read1.matches?(
|
42
|
-
expect(read1.matches?(
|
43
|
-
expect(read1.matches?(
|
44
|
-
|
45
|
-
expect(read2.matches?(
|
46
|
-
expect(read2.matches?(
|
47
|
-
expect(read2.matches?(
|
48
|
-
expect(read2.matches?(
|
49
|
-
expect(read2.matches?(
|
50
|
-
|
37
|
+
|
38
|
+
expect(read1.queue_name).to eq('default')
|
39
|
+
expect(read1.class_name).to eq('MyClass1')
|
40
|
+
expect(read2.queue_name).to eq('else_ok')
|
41
|
+
expect(read2.class_name).to eq('MyClass2')
|
42
|
+
|
43
|
+
expect(read1.matches?('bus_event_type' => 'event_one')).to eq(true)
|
44
|
+
expect(read1.matches?('bus_event_type' => 'event_one1')).to eq(false)
|
45
|
+
expect(read1.matches?('bus_event_type' => 'aevent_one')).to eq(false)
|
46
|
+
|
47
|
+
expect(read2.matches?('bus_event_type' => 'ahere')).to eq(true)
|
48
|
+
expect(read2.matches?('bus_event_type' => 'bhere')).to eq(true)
|
49
|
+
expect(read2.matches?('bus_event_type' => 'qhere')).to eq(false)
|
50
|
+
expect(read2.matches?('bus_event_type' => 'abhere')).to eq(false)
|
51
|
+
expect(read2.matches?('bus_event_type' => '[ab]here')).to eq(false)
|
51
52
|
end
|
52
53
|
end
|
53
|
-
end
|
54
|
+
end
|
data/spec/matcher_spec.rb
CHANGED
@@ -1,143 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe Matcher do
|
5
|
-
it
|
7
|
+
it 'should already return false on empty filters' do
|
6
8
|
matcher = Matcher.new({})
|
7
|
-
expect(matcher.matches?({})).to
|
9
|
+
expect(matcher.matches?({})).to eq(false)
|
8
10
|
expect(matcher.matches?(nil)).to eq(false)
|
9
|
-
expect(matcher.matches?(
|
11
|
+
expect(matcher.matches?('name' => 'val')).to eq(false)
|
10
12
|
end
|
11
13
|
|
12
|
-
it
|
13
|
-
matcher = Matcher.new(
|
14
|
+
it 'should not crash if nil inputs' do
|
15
|
+
matcher = Matcher.new('name' => 'val')
|
14
16
|
expect(matcher.matches?(nil)).to eq(false)
|
15
17
|
end
|
16
18
|
|
17
|
-
it
|
18
|
-
matcher = Matcher.new(
|
19
|
-
expect(matcher.matches?(
|
20
|
-
expect(matcher.matches?(
|
21
|
-
expect(matcher.matches?(
|
19
|
+
it 'string filter to/from redis' do
|
20
|
+
matcher = Matcher.new('name' => 'val')
|
21
|
+
expect(matcher.matches?('name' => 'val')).to eq(true)
|
22
|
+
expect(matcher.matches?('name' => ' val')).to eq(false)
|
23
|
+
expect(matcher.matches?('name' => 'zval')).to eq(false)
|
22
24
|
end
|
23
25
|
|
24
|
-
it
|
25
|
-
matcher = Matcher.new(
|
26
|
-
expect(matcher.matches?(
|
27
|
-
expect(matcher.matches?(
|
28
|
-
expect(matcher.matches?(
|
29
|
-
expect(matcher.matches?(
|
30
|
-
expect(matcher.matches?(
|
26
|
+
it 'regex filter' do
|
27
|
+
matcher = Matcher.new('name' => /^[cb]a+t/)
|
28
|
+
expect(matcher.matches?('name' => 'cat')).to eq(true)
|
29
|
+
expect(matcher.matches?('name' => 'bat')).to eq(true)
|
30
|
+
expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
|
31
|
+
expect(matcher.matches?('name' => 'ct')).to eq(false)
|
32
|
+
expect(matcher.matches?('name' => 'bcat')).to eq(false)
|
31
33
|
end
|
32
34
|
|
33
|
-
it
|
34
|
-
matcher = Matcher.new(
|
35
|
-
expect(matcher.matches?(
|
36
|
-
expect(matcher.matches?(
|
37
|
-
expect(matcher.matches?(
|
38
|
-
expect(matcher.matches?(
|
35
|
+
it 'present filter' do
|
36
|
+
matcher = Matcher.new('name' => :present)
|
37
|
+
expect(matcher.matches?('name' => '')).to eq(false)
|
38
|
+
expect(matcher.matches?('name' => 'cat')).to eq(true)
|
39
|
+
expect(matcher.matches?('name' => 'bear')).to eq(true)
|
40
|
+
expect(matcher.matches?('other' => 'bear')).to eq(false)
|
39
41
|
end
|
40
42
|
|
41
|
-
it
|
42
|
-
matcher = Matcher.new(
|
43
|
-
expect(matcher.matches?(
|
44
|
-
expect(matcher.matches?(
|
45
|
-
expect(matcher.matches?(
|
46
|
-
expect(matcher.matches?(
|
47
|
-
expect(matcher.matches?(
|
48
|
-
expect(matcher.matches?(
|
43
|
+
it 'blank filter' do
|
44
|
+
matcher = Matcher.new('name' => :blank)
|
45
|
+
expect(matcher.matches?('name' => nil)).to eq(true)
|
46
|
+
expect(matcher.matches?('other' => 'bear')).to eq(true)
|
47
|
+
expect(matcher.matches?('name' => '')).to eq(true)
|
48
|
+
expect(matcher.matches?('name' => ' ')).to eq(true)
|
49
|
+
expect(matcher.matches?('name' => 'bear')).to eq(false)
|
50
|
+
expect(matcher.matches?('name' => ' s ')).to eq(false)
|
49
51
|
end
|
50
52
|
|
51
|
-
it
|
52
|
-
matcher = Matcher.new(
|
53
|
-
expect(matcher.matches?(
|
54
|
-
expect(matcher.matches?(
|
55
|
-
expect(matcher.matches?(
|
56
|
-
expect(matcher.matches?(
|
57
|
-
expect(matcher.matches?(
|
53
|
+
it 'nil filter' do
|
54
|
+
matcher = Matcher.new('name' => :nil)
|
55
|
+
expect(matcher.matches?('name' => nil)).to eq(true)
|
56
|
+
expect(matcher.matches?('other' => 'bear')).to eq(true)
|
57
|
+
expect(matcher.matches?('name' => '')).to eq(false)
|
58
|
+
expect(matcher.matches?('name' => ' ')).to eq(false)
|
59
|
+
expect(matcher.matches?('name' => 'bear')).to eq(false)
|
58
60
|
end
|
59
61
|
|
60
|
-
it
|
61
|
-
matcher = Matcher.new(
|
62
|
-
expect(matcher.matches?(
|
63
|
-
expect(matcher.matches?(
|
64
|
-
expect(matcher.matches?(
|
65
|
-
expect(matcher.matches?(
|
66
|
-
expect(matcher.matches?(
|
62
|
+
it 'key filter' do
|
63
|
+
matcher = Matcher.new('name' => :key)
|
64
|
+
expect(matcher.matches?('name' => nil)).to eq(true)
|
65
|
+
expect(matcher.matches?('other' => 'bear')).to eq(false)
|
66
|
+
expect(matcher.matches?('name' => '')).to eq(true)
|
67
|
+
expect(matcher.matches?('name' => ' ')).to eq(true)
|
68
|
+
expect(matcher.matches?('name' => 'bear')).to eq(true)
|
67
69
|
end
|
68
70
|
|
69
|
-
it
|
70
|
-
matcher = Matcher.new(
|
71
|
-
expect(matcher.matches?(
|
72
|
-
expect(matcher.matches?(
|
73
|
-
expect(matcher.matches?(
|
74
|
-
expect(matcher.matches?(
|
75
|
-
expect(matcher.matches?(
|
76
|
-
expect(matcher.matches?(
|
71
|
+
it 'empty filter' do
|
72
|
+
matcher = Matcher.new('name' => :empty)
|
73
|
+
expect(matcher.matches?('name' => nil)).to eq(false)
|
74
|
+
expect(matcher.matches?('other' => 'bear')).to eq(false)
|
75
|
+
expect(matcher.matches?('name' => '')).to eq(true)
|
76
|
+
expect(matcher.matches?('name' => ' ')).to eq(false)
|
77
|
+
expect(matcher.matches?('name' => 'bear')).to eq(false)
|
78
|
+
expect(matcher.matches?('name' => ' s ')).to eq(false)
|
77
79
|
end
|
78
80
|
|
79
|
-
it
|
80
|
-
matcher = Matcher.new(
|
81
|
-
expect(matcher.matches?(
|
82
|
-
expect(matcher.matches?(
|
83
|
-
expect(matcher.matches?(
|
84
|
-
expect(matcher.matches?(
|
85
|
-
expect(matcher.matches?(
|
86
|
-
expect(matcher.matches?(
|
81
|
+
it 'value filter' do
|
82
|
+
matcher = Matcher.new('name' => :value)
|
83
|
+
expect(matcher.matches?('name' => nil)).to eq(false)
|
84
|
+
expect(matcher.matches?('other' => 'bear')).to eq(false)
|
85
|
+
expect(matcher.matches?('name' => '')).to eq(true)
|
86
|
+
expect(matcher.matches?('name' => ' ')).to eq(true)
|
87
|
+
expect(matcher.matches?('name' => 'bear')).to eq(true)
|
88
|
+
expect(matcher.matches?('name' => ' s ')).to eq(true)
|
87
89
|
end
|
88
90
|
|
89
|
-
it
|
90
|
-
matcher = Matcher.new(
|
91
|
-
expect(matcher.matches?(
|
92
|
-
expect(matcher.matches?(
|
93
|
-
expect(matcher.matches?(
|
94
|
-
expect(matcher.matches?(
|
95
|
-
expect(matcher.matches?(
|
91
|
+
it 'multiple filters' do
|
92
|
+
matcher = Matcher.new('name' => /^[cb]a+t/, 'state' => 'sleeping')
|
93
|
+
expect(matcher.matches?('state' => 'sleeping', 'name' => 'cat')).to eq(true)
|
94
|
+
expect(matcher.matches?('state' => 'awake', 'name' => 'cat')).to eq(false)
|
95
|
+
expect(matcher.matches?('state' => 'sleeping', 'name' => 'bat')).to eq(true)
|
96
|
+
expect(matcher.matches?('state' => 'sleeping', 'name' => 'bear')).to eq(false)
|
97
|
+
expect(matcher.matches?('state' => 'awake', 'name' => 'bear')).to eq(false)
|
96
98
|
end
|
97
99
|
|
98
|
-
it
|
99
|
-
matcher = Matcher.new(
|
100
|
-
expect(matcher.matches?(
|
101
|
-
expect(matcher.matches?(
|
102
|
-
expect(matcher.matches?(
|
103
|
-
expect(matcher.matches?(
|
104
|
-
expect(matcher.matches?(
|
100
|
+
it 'regex should go back and forth into redis' do
|
101
|
+
matcher = Matcher.new('name' => /^[cb]a+t/)
|
102
|
+
expect(matcher.matches?('name' => 'cat')).to eq(true)
|
103
|
+
expect(matcher.matches?('name' => 'bat')).to eq(true)
|
104
|
+
expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
|
105
|
+
expect(matcher.matches?('name' => 'ct')).to eq(false)
|
106
|
+
expect(matcher.matches?('name' => 'bcat')).to eq(false)
|
105
107
|
|
106
|
-
QueueBus.redis { |redis| redis.set(
|
107
|
-
redis = QueueBus.redis { |redis| redis.get(
|
108
|
+
QueueBus.redis { |redis| redis.set('temp1', QueueBus::Util.encode(matcher.to_redis)) }
|
109
|
+
redis = QueueBus.redis { |redis| redis.get('temp1') }
|
108
110
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
109
|
-
expect(matcher.matches?(
|
110
|
-
expect(matcher.matches?(
|
111
|
-
expect(matcher.matches?(
|
112
|
-
expect(matcher.matches?(
|
113
|
-
expect(matcher.matches?(
|
114
|
-
|
115
|
-
QueueBus.redis { |redis| redis.set(
|
116
|
-
redis = QueueBus.redis { |redis| redis.get(
|
111
|
+
expect(matcher.matches?('name' => 'cat')).to eq(true)
|
112
|
+
expect(matcher.matches?('name' => 'bat')).to eq(true)
|
113
|
+
expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
|
114
|
+
expect(matcher.matches?('name' => 'ct')).to eq(false)
|
115
|
+
expect(matcher.matches?('name' => 'bcat')).to eq(false)
|
116
|
+
|
117
|
+
QueueBus.redis { |redis| redis.set('temp2', QueueBus::Util.encode(matcher.to_redis)) }
|
118
|
+
redis = QueueBus.redis { |redis| redis.get('temp2') }
|
117
119
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
118
|
-
expect(matcher.matches?(
|
119
|
-
expect(matcher.matches?(
|
120
|
-
expect(matcher.matches?(
|
121
|
-
expect(matcher.matches?(
|
122
|
-
expect(matcher.matches?(
|
120
|
+
expect(matcher.matches?('name' => 'cat')).to eq(true)
|
121
|
+
expect(matcher.matches?('name' => 'bat')).to eq(true)
|
122
|
+
expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
|
123
|
+
expect(matcher.matches?('name' => 'ct')).to eq(false)
|
124
|
+
expect(matcher.matches?('name' => 'bcat')).to eq(false)
|
123
125
|
end
|
124
126
|
|
125
|
-
it
|
126
|
-
matcher = Matcher.new(
|
127
|
-
expect(matcher.matches?(
|
128
|
-
expect(matcher.matches?(
|
127
|
+
it 'special value should go back and forth into redis' do
|
128
|
+
matcher = Matcher.new('name' => :blank)
|
129
|
+
expect(matcher.matches?('name' => 'cat')).to eq(false)
|
130
|
+
expect(matcher.matches?('name' => '')).to eq(true)
|
129
131
|
|
130
|
-
QueueBus.redis { |redis| redis.set(
|
131
|
-
redis= QueueBus.redis { |redis| redis.get(
|
132
|
+
QueueBus.redis { |redis| redis.set('temp1', QueueBus::Util.encode(matcher.to_redis)) }
|
133
|
+
redis = QueueBus.redis { |redis| redis.get('temp1') }
|
132
134
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
133
|
-
expect(matcher.matches?(
|
134
|
-
expect(matcher.matches?(
|
135
|
+
expect(matcher.matches?('name' => 'cat')).to eq(false)
|
136
|
+
expect(matcher.matches?('name' => '')).to eq(true)
|
135
137
|
|
136
|
-
QueueBus.redis { |redis| redis.set(
|
137
|
-
redis= QueueBus.redis { |redis| redis.get(
|
138
|
+
QueueBus.redis { |redis| redis.set('temp2', QueueBus::Util.encode(matcher.to_redis)) }
|
139
|
+
redis = QueueBus.redis { |redis| redis.get('temp2') }
|
138
140
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
139
|
-
expect(matcher.matches?(
|
140
|
-
expect(matcher.matches?(
|
141
|
+
expect(matcher.matches?('name' => 'cat')).to eq(false)
|
142
|
+
expect(matcher.matches?('name' => '')).to eq(true)
|
141
143
|
end
|
142
144
|
end
|
143
145
|
end
|
data/spec/publish_spec.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
|
+
describe 'Publishing an event' do
|
5
6
|
before(:each) do
|
6
7
|
Timecop.freeze
|
7
|
-
allow(QueueBus).to receive(:generate_uuid).and_return(
|
8
|
+
allow(QueueBus).to receive(:generate_uuid).and_return('idfhlkj')
|
8
9
|
end
|
9
10
|
after(:each) do
|
10
11
|
Timecop.return
|
11
12
|
end
|
12
|
-
let(:bus_attrs)
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
let(:bus_attrs) do
|
14
|
+
{ 'bus_class_proxy' => 'QueueBus::Driver',
|
15
|
+
'bus_published_at' => Time.now.to_i,
|
16
|
+
'bus_id' => "#{Time.now.to_i}-idfhlkj",
|
17
|
+
'bus_app_hostname' => Socket.gethostname }
|
18
|
+
end
|
16
19
|
|
17
|
-
it
|
18
|
-
hash = {:one => 1,
|
19
|
-
event_name =
|
20
|
+
it 'should add it to Redis' do
|
21
|
+
hash = { :one => 1, 'two' => 'here', 'id' => 12 }
|
22
|
+
event_name = 'event_name'
|
20
23
|
|
21
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
24
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
22
25
|
expect(val).to eq(nil)
|
23
26
|
|
24
27
|
QueueBus.publish(event_name, hash)
|
25
28
|
|
26
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
29
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
27
30
|
hash = JSON.parse(val)
|
28
|
-
expect(hash[
|
29
|
-
expect(hash[
|
30
|
-
expect(JSON.parse(hash[
|
31
|
-
|
31
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
32
|
+
expect(hash['args'].size).to eq(1)
|
33
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_event_type' => event_name, 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(bus_attrs))
|
32
34
|
end
|
33
35
|
|
34
|
-
it
|
35
|
-
hash = {:one => 1,
|
36
|
-
event_name =
|
36
|
+
it 'should use the id if given' do
|
37
|
+
hash = { :one => 1, 'two' => 'here', 'bus_id' => 'app-given' }
|
38
|
+
event_name = 'event_name'
|
37
39
|
|
38
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
40
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
39
41
|
expect(val).to eq(nil)
|
40
42
|
|
41
43
|
QueueBus.publish(event_name, hash)
|
42
44
|
|
43
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
45
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
44
46
|
hash = JSON.parse(val)
|
45
|
-
expect(hash[
|
46
|
-
expect(hash[
|
47
|
-
expect(JSON.parse(hash[
|
47
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
48
|
+
expect(hash['args'].size).to eq(1)
|
49
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_event_type' => event_name, 'two' => 'here', 'one' => 1 }.merge(bus_attrs).merge('bus_id' => 'app-given'))
|
48
50
|
end
|
49
51
|
|
50
|
-
it
|
52
|
+
it 'should add metadata via callback' do
|
51
53
|
myval = 0
|
52
54
|
QueueBus.before_publish = lambda { |att|
|
53
|
-
att[
|
55
|
+
att['mine'] = 4
|
54
56
|
myval += 1
|
55
57
|
}
|
56
58
|
|
57
|
-
hash = {:one => 1,
|
58
|
-
event_name =
|
59
|
+
hash = { :one => 1, 'two' => 'here', 'bus_id' => 'app-given' }
|
60
|
+
event_name = 'event_name'
|
59
61
|
|
60
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
62
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
61
63
|
expect(val).to eq(nil)
|
62
64
|
|
63
65
|
QueueBus.publish(event_name, hash)
|
64
66
|
|
65
|
-
|
66
|
-
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
67
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
67
68
|
hash = JSON.parse(val)
|
68
|
-
att = JSON.parse(hash[
|
69
|
-
expect(att[
|
69
|
+
att = JSON.parse(hash['args'].first)
|
70
|
+
expect(att['mine']).to eq(4)
|
70
71
|
expect(myval).to eq(1)
|
71
72
|
end
|
72
73
|
|
73
|
-
it
|
74
|
+
it 'should set the timezone and locale if available' do
|
74
75
|
expect(defined?(I18n)).to be_nil
|
75
76
|
expect(Time.respond_to?(:zone)).to eq(false)
|
76
77
|
|
77
|
-
stub_const(
|
78
|
-
allow(I18n).to receive(:locale).and_return(
|
78
|
+
stub_const('I18n', Class.new)
|
79
|
+
allow(I18n).to receive(:locale).and_return('jp')
|
79
80
|
|
80
|
-
allow(Time).to receive(:zone).and_return(double('zone', :
|
81
|
+
allow(Time).to receive(:zone).and_return(double('zone', name: 'EST'))
|
81
82
|
|
82
|
-
hash = {:one => 1,
|
83
|
-
event_name =
|
83
|
+
hash = { :one => 1, 'two' => 'here', 'bus_id' => 'app-given' }
|
84
|
+
event_name = 'event_name'
|
84
85
|
|
85
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
86
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
86
87
|
expect(val).to eq(nil)
|
87
88
|
|
88
89
|
QueueBus.publish(event_name, hash)
|
89
90
|
|
90
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
91
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
91
92
|
hash = JSON.parse(val)
|
92
|
-
expect(hash[
|
93
|
-
att = JSON.parse(hash[
|
94
|
-
expect(att[
|
95
|
-
expect(att[
|
93
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
94
|
+
att = JSON.parse(hash['args'].first)
|
95
|
+
expect(att['bus_locale']).to eq('jp')
|
96
|
+
expect(att['bus_timezone']).to eq('EST')
|
96
97
|
end
|
97
|
-
|
98
98
|
end
|