fastly_nsq 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfbb2df1f2bb5e0a03516595b655c65c72238697
4
- data.tar.gz: db467a7f87cf17d1dd6d69b577d8c8c051c87028
3
+ metadata.gz: 8ccbc7fd7e6fa179bd882b2484044920665c0a3a
4
+ data.tar.gz: eb2b73af286d71f8e8a4c07de67801ebf50768fb
5
5
  SHA512:
6
- metadata.gz: e07fc37bed4ef892de6ed12048c4ae9d8217b9f55f0ed08a1a3b16b118264be3e2a757b0fd9b35c433399b82ada9731ddaf026f204f507055fa283769fd9a780
7
- data.tar.gz: 28044043d848e2143b517db10a5d2d6bbec39e244d18af1d313e38d5268ae0853e802d2c6c77aaeb8c77ee4bf560cfe02cae5447a8984bbb92459310a8264acd
6
+ metadata.gz: 023c35498c520e22c39fae392a1d912297b66371bf177aca8ee3a8c6a74941b5024c078a91f576b3659bef3efcddd7372bff70b363f040a7ced73f8076ca0b1f
7
+ data.tar.gz: d9bd4a185e4540466e8c4dbe64aef1e6cda7627019c98860d1a482052ca3fdf1beee7d75f2821b966b19437a81599e7b61dff631fe3b6dcf3c204f9cd0ec41ff
@@ -1,16 +1,12 @@
1
1
  module FakeMessageQueue
2
- @@queue = []
2
+ @@queue = Queue.new
3
3
 
4
4
  def self.queue
5
5
  @@queue
6
6
  end
7
7
 
8
- def self.queue=(message)
9
- @@queue = message
10
- end
11
-
12
8
  def self.reset!
13
- self.queue = []
9
+ self.queue.clear
14
10
  end
15
11
 
16
12
  class Producer
@@ -1,3 +1,3 @@
1
1
  module FastlyNsq
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -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 array' do
6
- expect(FakeMessageQueue.queue).to eq []
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 = ['hello']
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 = ['hello']
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
- it 'returns the last message off of the queue' do
96
- message = FakeMessageQueue::Message.new('hello')
97
- FakeMessageQueue.queue = [message]
98
- topic = 'death_star'
99
- channel = 'star_killer_base'
100
-
101
- consumer = FakeMessageQueue::Consumer.new(
102
- nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
103
- topic: topic,
104
- channel: channel,
105
- )
106
- popped_message = consumer.pop
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
- expect(popped_message). to eq message
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
- use_real_connection do
8
- allow(Nsq::Consumer).to receive(:new)
9
- topic = 'death_star'
10
- channel = 'star_killer_base'
7
+ allow(Nsq::Consumer).to receive(:new)
8
+ topic = 'death_star'
9
+ channel = 'star_killer_base'
11
10
 
12
- MessageQueue::Consumer.new(topic: topic, channel: channel).connection
11
+ MessageQueue::Consumer.new(topic: topic, channel: channel).connection
13
12
 
14
- expect(Nsq::Consumer).to have_received(:new).
15
- with(
16
- nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
17
- topic: topic,
18
- channel: channel,
19
- ).at_least(:once)
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
- use_fake_connection do
27
- allow(FakeMessageQueue::Consumer).to receive(:new)
28
- topic = 'death_star'
29
- channel = 'star_killer_base'
24
+ allow(FakeMessageQueue::Consumer).to receive(:new)
25
+ topic = 'death_star'
26
+ channel = 'star_killer_base'
30
27
 
31
- MessageQueue::Consumer.new(topic: topic, channel: channel).connection
28
+ MessageQueue::Consumer.new(topic: topic, channel: channel).connection
32
29
 
33
- expect(FakeMessageQueue::Consumer).to have_received(:new).
34
- with(
35
- nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
36
- topic: topic,
37
- channel: channel,
38
- ).at_least(:once)
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
- use_real_connection do
60
- consumer = double('Consumer', connection: nil, terminate: nil)
61
- allow(Nsq::Consumer).to receive(:new).and_return(consumer)
62
- topic = 'death_star'
63
- channel = 'star_killer_base'
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
- live_consumer = MessageQueue::Consumer.new(params)
67
- live_consumer.connection
68
- live_consumer.terminate
61
+ live_consumer = MessageQueue::Consumer.new(params)
62
+ live_consumer.connection
63
+ live_consumer.terminate
69
64
 
70
- expect(consumer).to have_received(:terminate)
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
- use_fake_connection do
78
- consumer = double('Consumer', connection: nil, terminate: nil)
79
- allow(FakeMessageQueue::Consumer).to receive(:new).and_return(consumer)
80
- topic = 'death_star'
81
- channel = 'star_killer_base'
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
- live_consumer = MessageQueue::Consumer.new(params)
85
- live_consumer.connection
86
- live_consumer.terminate
77
+ live_consumer = MessageQueue::Consumer.new(params)
78
+ live_consumer.connection
79
+ live_consumer.terminate
87
80
 
88
- expect(consumer).to have_received(:terminate)
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 = 'minitest'
12
- channel = 'northstar'
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 = 'minitest'
30
- channel = 'northstar'
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 = 'minitest'
46
- channel = 'northstar'
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 = 'minitest'
64
- channel = 'northstar'
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
- # Note: We are not testing the SIGINT case because it orphans the test
74
- # Ruby process and is sort of meaningless as a test.
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
- use_real_connection do
8
- allow(Nsq::Producer).to receive(:new)
9
- topic = 'death_star'
7
+ allow(Nsq::Producer).to receive(:new)
8
+ topic = 'death_star'
10
9
 
11
- MessageQueue::Producer.new(topic: topic).connection
10
+ MessageQueue::Producer.new(topic: topic).connection
12
11
 
13
- expect(Nsq::Producer).to have_received(:new).
14
- with(
15
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
16
- topic: topic,
17
- ).at_least(:once)
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
- use_fake_connection do
25
- allow(FakeMessageQueue::Producer).to receive(:new)
26
- topic = 'death_star'
22
+ allow(FakeMessageQueue::Producer).to receive(:new)
23
+ topic = 'death_star'
27
24
 
28
- MessageQueue::Producer.new(topic: topic).connection
25
+ MessageQueue::Producer.new(topic: topic).connection
29
26
 
30
- expect(FakeMessageQueue::Producer).to have_received(:new).
31
- with(
32
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
33
- topic: topic,
34
- ).at_least(:once)
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
- use_real_connection do
55
- producer = double('Producer', connection: nil, terminate: nil)
56
- allow(Nsq::Producer).to receive(:new).and_return(producer)
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
- live_producer = MessageQueue::Producer.new(topic: topic)
60
- live_producer.connection
61
- live_producer.terminate
54
+ live_producer = MessageQueue::Producer.new(topic: topic)
55
+ live_producer.connection
56
+ live_producer.terminate
62
57
 
63
- expect(producer).to have_received(:terminate)
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
- use_fake_connection do
71
- producer = double('Producer', connection: nil, terminate: nil)
72
- allow(FakeMessageQueue::Producer).to receive(:new).and_return(producer)
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
- live_producer = MessageQueue::Producer.new(topic: topic)
76
- live_producer.connection
77
- live_producer.terminate
68
+ live_producer = MessageQueue::Producer.new(topic: topic)
69
+ live_producer.connection
70
+ live_producer.terminate
78
71
 
79
- expect(producer).to have_received(:terminate)
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
- MessageQueue::TRUTHY_VALUES.each do |yes|
8
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(yes)
7
+ strategy = Strategy.for_queue
9
8
 
10
- strategy = Strategy.for_queue
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
- MessageQueue::FALSY_VALUES.each do |no|
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
- expect(strategy).to eq Nsq
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.1
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-02-26 00:00:00.000000000 Z
12
+ date: 2016-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print