fastly_nsq 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fastly_nsq/fake_message_queue.rb +2 -6
- data/lib/fastly_nsq/version.rb +1 -1
- data/spec/lib/fastly_nsq/fake_message_queue_spec.rb +42 -17
- data/spec/lib/fastly_nsq/message_queue/consumer_spec.rb +42 -50
- data/spec/lib/fastly_nsq/message_queue/listener_spec.rb +29 -11
- data/spec/lib/fastly_nsq/message_queue/producer_spec.rb +34 -42
- data/spec/lib/fastly_nsq/message_queue/strategy_spec.rb +6 -14
- data/spec/spec_helper.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ccbc7fd7e6fa179bd882b2484044920665c0a3a
|
4
|
+
data.tar.gz: eb2b73af286d71f8e8a4c07de67801ebf50768fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 023c35498c520e22c39fae392a1d912297b66371bf177aca8ee3a8c6a74941b5024c078a91f576b3659bef3efcddd7372bff70b363f040a7ced73f8076ca0b1f
|
7
|
+
data.tar.gz: d9bd4a185e4540466e8c4dbe64aef1e6cda7627019c98860d1a482052ca3fdf1beee7d75f2821b966b19437a81599e7b61dff631fe3b6dcf3c204f9cd0ec41ff
|
data/lib/fastly_nsq/version.rb
CHANGED
@@ -2,14 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe FakeMessageQueue do
|
4
4
|
describe '@@queue' do
|
5
|
-
it 'is initalized as an empty
|
6
|
-
|
5
|
+
it 'is initalized as an empty Ruby Queue' do
|
6
|
+
queue = FakeMessageQueue.queue
|
7
|
+
|
8
|
+
expect(queue).to be_a Thread::Queue
|
9
|
+
expect(queue).to be_empty
|
7
10
|
end
|
8
11
|
end
|
9
12
|
|
10
13
|
describe '.reset!' do
|
11
14
|
it 'resets the fake message queue' do
|
12
|
-
FakeMessageQueue.queue
|
15
|
+
FakeMessageQueue.queue.push('hello')
|
13
16
|
expect(FakeMessageQueue.queue.size).to eq 1
|
14
17
|
|
15
18
|
FakeMessageQueue.reset!
|
@@ -76,7 +79,7 @@ RSpec.describe FakeMessageQueue::Consumer do
|
|
76
79
|
|
77
80
|
describe '#size' do
|
78
81
|
it 'tells you how many messages are in the queue' do
|
79
|
-
FakeMessageQueue.queue
|
82
|
+
FakeMessageQueue.queue.push('hello')
|
80
83
|
topic = 'death_star'
|
81
84
|
channel = 'star_killer_base'
|
82
85
|
|
@@ -92,20 +95,42 @@ RSpec.describe FakeMessageQueue::Consumer do
|
|
92
95
|
end
|
93
96
|
|
94
97
|
describe '#pop' do
|
95
|
-
|
96
|
-
message
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
98
|
+
context 'when there is a message on the queue' do
|
99
|
+
it 'returns the last message off of the queue' do
|
100
|
+
message = FakeMessageQueue::Message.new('hello')
|
101
|
+
FakeMessageQueue.queue.push(message)
|
102
|
+
topic = 'death_star'
|
103
|
+
channel = 'star_killer_base'
|
104
|
+
|
105
|
+
consumer = FakeMessageQueue::Consumer.new(
|
106
|
+
nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
|
107
|
+
topic: topic,
|
108
|
+
channel: channel,
|
109
|
+
)
|
110
|
+
popped_message = consumer.pop
|
111
|
+
|
112
|
+
expect(popped_message).to eq message
|
113
|
+
end
|
114
|
+
end
|
107
115
|
|
108
|
-
|
116
|
+
context 'when there no message on the queue' do
|
117
|
+
it 'blocks on the process, waiting for a message ' do
|
118
|
+
FakeMessageQueue.reset!
|
119
|
+
topic = 'death_star'
|
120
|
+
channel = 'star_killer_base'
|
121
|
+
|
122
|
+
consumer = FakeMessageQueue::Consumer.new(
|
123
|
+
nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
|
124
|
+
topic: topic,
|
125
|
+
channel: channel,
|
126
|
+
)
|
127
|
+
|
128
|
+
expect {
|
129
|
+
Timeout::timeout(0.1) do
|
130
|
+
consumer.pop
|
131
|
+
end
|
132
|
+
}.to raise_error(Timeout::Error)
|
133
|
+
end
|
109
134
|
end
|
110
135
|
end
|
111
136
|
|
@@ -2,41 +2,37 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe MessageQueue::Consumer do
|
4
4
|
describe '#connection' do
|
5
|
-
describe 'when using the real queue' do
|
5
|
+
describe 'when using the real queue', fake_queue: false do
|
6
6
|
it 'returns an instance of the queue consumer' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
channel = 'star_killer_base'
|
7
|
+
allow(Nsq::Consumer).to receive(:new)
|
8
|
+
topic = 'death_star'
|
9
|
+
channel = 'star_killer_base'
|
11
10
|
|
12
|
-
|
11
|
+
MessageQueue::Consumer.new(topic: topic, channel: channel).connection
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
13
|
+
expect(Nsq::Consumer).to have_received(:new).
|
14
|
+
with(
|
15
|
+
nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
|
16
|
+
topic: topic,
|
17
|
+
channel: channel,
|
18
|
+
).at_least(:once)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
describe 'when using the fake queue' do
|
22
|
+
describe 'when using the fake queue', fake_queue: true do
|
25
23
|
it 'returns an instance of the queue consumer' do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
channel = 'star_killer_base'
|
24
|
+
allow(FakeMessageQueue::Consumer).to receive(:new)
|
25
|
+
topic = 'death_star'
|
26
|
+
channel = 'star_killer_base'
|
30
27
|
|
31
|
-
|
28
|
+
MessageQueue::Consumer.new(topic: topic, channel: channel).connection
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
30
|
+
expect(FakeMessageQueue::Consumer).to have_received(:new).
|
31
|
+
with(
|
32
|
+
nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
|
33
|
+
topic: topic,
|
34
|
+
channel: channel,
|
35
|
+
).at_least(:once)
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|
@@ -54,39 +50,35 @@ RSpec.describe MessageQueue::Consumer do
|
|
54
50
|
end
|
55
51
|
|
56
52
|
describe '#terminate' do
|
57
|
-
describe 'when using the real queue' do
|
53
|
+
describe 'when using the real queue', fake_queue: false do
|
58
54
|
it 'closes the connection' do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
params = { topic: topic, channel: channel }
|
55
|
+
consumer = double('Consumer', connection: nil, terminate: nil)
|
56
|
+
allow(Nsq::Consumer).to receive(:new).and_return(consumer)
|
57
|
+
topic = 'death_star'
|
58
|
+
channel = 'star_killer_base'
|
59
|
+
params = { topic: topic, channel: channel }
|
65
60
|
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
live_consumer = MessageQueue::Consumer.new(params)
|
62
|
+
live_consumer.connection
|
63
|
+
live_consumer.terminate
|
69
64
|
|
70
|
-
|
71
|
-
end
|
65
|
+
expect(consumer).to have_received(:terminate)
|
72
66
|
end
|
73
67
|
end
|
74
68
|
|
75
|
-
describe 'when using the fake queue' do
|
69
|
+
describe 'when using the fake queue', fake_queue: true do
|
76
70
|
it 'closes the connection' do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
params = { topic: topic, channel: channel }
|
71
|
+
consumer = double('Consumer', connection: nil, terminate: nil)
|
72
|
+
allow(FakeMessageQueue::Consumer).to receive(:new).and_return(consumer)
|
73
|
+
topic = 'death_star'
|
74
|
+
channel = 'star_killer_base'
|
75
|
+
params = { topic: topic, channel: channel }
|
83
76
|
|
84
|
-
|
85
|
-
|
86
|
-
|
77
|
+
live_consumer = MessageQueue::Consumer.new(params)
|
78
|
+
live_consumer.connection
|
79
|
+
live_consumer.terminate
|
87
80
|
|
88
|
-
|
89
|
-
end
|
81
|
+
expect(consumer).to have_received(:terminate)
|
90
82
|
end
|
91
83
|
end
|
92
84
|
end
|
@@ -8,8 +8,8 @@ RSpec.describe MessageQueue::Listener do
|
|
8
8
|
connection = double('Connection', pop: message, terminate: nil)
|
9
9
|
consumer = double('Consumer', connection: connection)
|
10
10
|
allow(MessageQueue::Consumer).to receive(:new).and_return(consumer)
|
11
|
-
topic = '
|
12
|
-
channel = '
|
11
|
+
topic = 'testing_topic'
|
12
|
+
channel = 'testing_channel'
|
13
13
|
|
14
14
|
MessageQueue::Listener.new(topic: topic, channel: channel).
|
15
15
|
process_next_message
|
@@ -26,8 +26,8 @@ RSpec.describe MessageQueue::Listener do
|
|
26
26
|
connection = double('Connection', pop: message, terminate: nil)
|
27
27
|
consumer = double('Consumer', connection: connection)
|
28
28
|
allow(MessageQueue::Consumer).to receive(:new).and_return(consumer)
|
29
|
-
topic = '
|
30
|
-
channel = '
|
29
|
+
topic = 'testing_topic'
|
30
|
+
channel = 'testing_channel'
|
31
31
|
|
32
32
|
MessageQueue::Listener.new(topic: topic, channel: channel).
|
33
33
|
process_next_message
|
@@ -42,14 +42,31 @@ RSpec.describe MessageQueue::Listener do
|
|
42
42
|
connection = double('Connection', pop: message, terminate: nil)
|
43
43
|
consumer = double('Consumer', connection: connection)
|
44
44
|
allow(MessageQueue::Consumer).to receive(:new).and_return(consumer)
|
45
|
-
topic = '
|
46
|
-
channel = '
|
45
|
+
topic = 'testing_topic'
|
46
|
+
channel = 'testing_channel'
|
47
47
|
|
48
48
|
MessageQueue::Listener.new(topic: topic, channel: channel).
|
49
49
|
process_next_message
|
50
50
|
|
51
51
|
expect(message).to have_received(:finish)
|
52
52
|
end
|
53
|
+
|
54
|
+
context 'when using the fake queue and it is empty' do
|
55
|
+
it 'blocks on the process, waiting for a message ' do
|
56
|
+
MessageQueue::TRUTHY_VALUES.each do |yes|
|
57
|
+
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(yes)
|
58
|
+
topic = 'testing_topic'
|
59
|
+
channel = 'testing_channel'
|
60
|
+
|
61
|
+
expect {
|
62
|
+
Timeout::timeout(0.1) do
|
63
|
+
MessageQueue::Listener.new(topic: topic, channel: channel).
|
64
|
+
process_next_message
|
65
|
+
end
|
66
|
+
}.to raise_error(Timeout::Error)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
53
70
|
end
|
54
71
|
|
55
72
|
describe '#go' do
|
@@ -60,8 +77,8 @@ RSpec.describe MessageQueue::Listener do
|
|
60
77
|
connection = double('Connection', pop: message, terminate: nil)
|
61
78
|
consumer = double('Consumer', connection: connection)
|
62
79
|
allow(MessageQueue::Consumer).to receive(:new).and_return(consumer)
|
63
|
-
topic = '
|
64
|
-
channel = '
|
80
|
+
topic = 'testing_topic'
|
81
|
+
channel = 'testing_channel'
|
65
82
|
|
66
83
|
pid = fork do
|
67
84
|
MessageQueue::Listener.new(topic: topic, channel: channel).go
|
@@ -69,9 +86,10 @@ RSpec.describe MessageQueue::Listener do
|
|
69
86
|
|
70
87
|
Process.kill('TERM', pid)
|
71
88
|
|
72
|
-
# Success for this test is to expect it to complete
|
73
|
-
#
|
74
|
-
#
|
89
|
+
# Success for this test is to expect it to complete.
|
90
|
+
#
|
91
|
+
# Additional Note: We are NOT testing the SIGINT case because it
|
92
|
+
# orphans the test's Ruby process and is thus meaningless as a test.
|
75
93
|
end
|
76
94
|
end
|
77
95
|
end
|
@@ -2,37 +2,33 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe MessageQueue::Producer do
|
4
4
|
describe '#connection' do
|
5
|
-
describe 'when using the real queue' do
|
5
|
+
describe 'when using the real queue', fake_queue: false do
|
6
6
|
it 'returns an instance of the queue producer' do
|
7
|
-
|
8
|
-
|
9
|
-
topic = 'death_star'
|
7
|
+
allow(Nsq::Producer).to receive(:new)
|
8
|
+
topic = 'death_star'
|
10
9
|
|
11
|
-
|
10
|
+
MessageQueue::Producer.new(topic: topic).connection
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
expect(Nsq::Producer).to have_received(:new).
|
13
|
+
with(
|
14
|
+
nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
|
15
|
+
topic: topic,
|
16
|
+
).at_least(:once)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
|
-
describe 'when using the fake queue' do
|
20
|
+
describe 'when using the fake queue', fake_queue: true do
|
23
21
|
it 'returns an instance of the queue producer' do
|
24
|
-
|
25
|
-
|
26
|
-
topic = 'death_star'
|
22
|
+
allow(FakeMessageQueue::Producer).to receive(:new)
|
23
|
+
topic = 'death_star'
|
27
24
|
|
28
|
-
|
25
|
+
MessageQueue::Producer.new(topic: topic).connection
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
27
|
+
expect(FakeMessageQueue::Producer).to have_received(:new).
|
28
|
+
with(
|
29
|
+
nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
|
30
|
+
topic: topic,
|
31
|
+
).at_least(:once)
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
@@ -49,35 +45,31 @@ RSpec.describe MessageQueue::Producer do
|
|
49
45
|
end
|
50
46
|
|
51
47
|
describe '#terminate' do
|
52
|
-
describe 'when using the real queue' do
|
48
|
+
describe 'when using the real queue', fake_queue: false do
|
53
49
|
it 'closes the connection' do
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
topic = 'death_star'
|
50
|
+
producer = double('Producer', connection: nil, terminate: nil)
|
51
|
+
allow(Nsq::Producer).to receive(:new).and_return(producer)
|
52
|
+
topic = 'death_star'
|
58
53
|
|
59
|
-
|
60
|
-
|
61
|
-
|
54
|
+
live_producer = MessageQueue::Producer.new(topic: topic)
|
55
|
+
live_producer.connection
|
56
|
+
live_producer.terminate
|
62
57
|
|
63
|
-
|
64
|
-
end
|
58
|
+
expect(producer).to have_received(:terminate)
|
65
59
|
end
|
66
60
|
end
|
67
61
|
|
68
|
-
describe 'when using the fake queue' do
|
62
|
+
describe 'when using the fake queue', fake_queue: true do
|
69
63
|
it 'closes the connection' do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
topic = 'death_star'
|
64
|
+
producer = double('Producer', connection: nil, terminate: nil)
|
65
|
+
allow(FakeMessageQueue::Producer).to receive(:new).and_return(producer)
|
66
|
+
topic = 'death_star'
|
74
67
|
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
live_producer = MessageQueue::Producer.new(topic: topic)
|
69
|
+
live_producer.connection
|
70
|
+
live_producer.terminate
|
78
71
|
|
79
|
-
|
80
|
-
end
|
72
|
+
expect(producer).to have_received(:terminate)
|
81
73
|
end
|
82
74
|
end
|
83
75
|
end
|
@@ -2,27 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Strategy do
|
4
4
|
describe '.for_queue' do
|
5
|
-
describe 'when using the fake queue' do
|
5
|
+
describe 'when using the fake queue', fake_queue: true do
|
6
6
|
it 'returns the strategy based on the ENV variable' do
|
7
|
-
|
8
|
-
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(yes)
|
7
|
+
strategy = Strategy.for_queue
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
expect(strategy).to eq FakeMessageQueue
|
13
|
-
end
|
9
|
+
expect(strategy).to eq FakeMessageQueue
|
14
10
|
end
|
15
11
|
end
|
16
12
|
|
17
|
-
describe 'when using the real queue' do
|
13
|
+
describe 'when using the real queue', fake_queue: false do
|
18
14
|
it 'returns the strategy based on the ENV variable' do
|
19
|
-
|
20
|
-
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(no)
|
21
|
-
|
22
|
-
strategy = Strategy.for_queue
|
15
|
+
strategy = Strategy.for_queue
|
23
16
|
|
24
|
-
|
25
|
-
end
|
17
|
+
expect(strategy).to eq Nsq
|
26
18
|
end
|
27
19
|
end
|
28
20
|
|
data/spec/spec_helper.rb
CHANGED
@@ -34,6 +34,22 @@ RSpec.configure do |config|
|
|
34
34
|
FakeMessageQueue.reset!
|
35
35
|
end
|
36
36
|
|
37
|
+
config.around(:each, fake_queue: true) do |example|
|
38
|
+
RSpec::Mocks.with_temporary_scope do
|
39
|
+
use_fake_connection do
|
40
|
+
example.run
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
config.around(:each, fake_queue: false) do |example|
|
46
|
+
RSpec::Mocks.with_temporary_scope do
|
47
|
+
use_real_connection do
|
48
|
+
example.run
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
37
53
|
def load_sample_environment_variables
|
38
54
|
env_file = File.open('env_configuration_for_local_gem_tests.yml')
|
39
55
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastly_nsq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommy O'Neil
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: awesome_print
|