fastly_nsq 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ccbc7fd7e6fa179bd882b2484044920665c0a3a
4
- data.tar.gz: eb2b73af286d71f8e8a4c07de67801ebf50768fb
3
+ metadata.gz: 675e3b849867520a11d52017b73a07381287abee
4
+ data.tar.gz: 6f6f61ed2785d5872e2ea944d88bafffdc1c7817
5
5
  SHA512:
6
- metadata.gz: 023c35498c520e22c39fae392a1d912297b66371bf177aca8ee3a8c6a74941b5024c078a91f576b3659bef3efcddd7372bff70b363f040a7ced73f8076ca0b1f
7
- data.tar.gz: d9bd4a185e4540466e8c4dbe64aef1e6cda7627019c98860d1a482052ca3fdf1beee7d75f2821b966b19437a81599e7b61dff631fe3b6dcf3c204f9cd0ec41ff
6
+ metadata.gz: 5c8e596008b721e62a78064d98e185dfeae6c2f176a995ffdf3835103d90b9bf1e537aa29a004c9acfdd9d3503961eecb998e9dcb6a7afaf9e6d46c3f6c3fc62
7
+ data.tar.gz: f386146874a9fd8ed2bcfeaff3a17fac5568b28873a55de583dda3f33b0ab821bc4a56a36008b5ad971be4e4a4d69ac3f7cb23d1fb2bb326721372e3d71c06c1
@@ -0,0 +1,30 @@
1
+ Reason for Change
2
+ ===================
3
+ Describe the big picture of your changes here to communicate why this pull
4
+ request should be accepted. If it fixes a bug or resolves a feature request,
5
+ be sure to link to that issue.
6
+
7
+ List of Changes
8
+ ===============
9
+ * Describe your changes
10
+ * As a concise list of items
11
+
12
+ Risks
13
+ =====
14
+ Describe any risks you see to existing systems this fix or feature might have
15
+ if those systems where to incorporate this change.
16
+
17
+ Checklist
18
+ =========
19
+ _Put an `x` in the boxes that apply.
20
+ You can also fill these out after creating the PR._
21
+
22
+ - [ ] I have linked to all relavant reference issues or work requests
23
+ - [ ] I have added tests that prove my fix is effective or that my feature works
24
+ - [ ] I have added or updated necessary documentation (if appropriate)
25
+ - [ ] Any dependent changes have been merged and published in downstream
26
+
27
+
28
+ Recommended Reviewers
29
+ =====================
30
+ @alieander, ...
@@ -10,6 +10,11 @@ require 'fastly_nsq/rake_task'
10
10
  #
11
11
  MessageQueue::RakeTask.new(:listen_task, [:topic, :channel])
12
12
 
13
+ ##
14
+ # In Rails, you can include the environment like so:
15
+ #
16
+ MessageQueue::RakeTask.new(:listen_task, [:topic, :channel] => :environment)
17
+
13
18
  ##
14
19
  # Topic and channel can also be preset in the task by passing a block and
15
20
  # assigning value like so. This is useful if you want a single purpose
@@ -1,12 +1,24 @@
1
1
  module FakeMessageQueue
2
- @@queue = Queue.new
2
+ @@logger = Logger.new(nil)
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
+
8
12
  def self.reset!
9
- self.queue.clear
13
+ self.queue = []
14
+ end
15
+
16
+ def self.logger=(logger)
17
+ @@logger = logger
18
+ end
19
+
20
+ def self.logger
21
+ @@logger
10
22
  end
11
23
 
12
24
  class Producer
@@ -30,11 +42,20 @@ module FakeMessageQueue
30
42
  end
31
43
 
32
44
  class Consumer
45
+ SECONDS_BETWEEN_QUEUE_CHECKS = 0.5
46
+
33
47
  def initialize(nsqlookupd:, topic:, channel:)
34
48
  end
35
49
 
36
50
  def pop
37
- queue.pop
51
+ message = nil
52
+
53
+ until message do
54
+ message = queue.pop
55
+ sleep SECONDS_BETWEEN_QUEUE_CHECKS
56
+ end
57
+
58
+ message
38
59
  end
39
60
 
40
61
  def size
@@ -8,4 +8,16 @@ require_relative 'message_queue/strategy'
8
8
  module MessageQueue
9
9
  FALSY_VALUES = [false, 0, '0', 'false', 'FALSE', 'off', 'OFF', nil]
10
10
  TRUTHY_VALUES = [true, 1, '1', 'true', 'TRUE', 'on', 'ON']
11
+
12
+ def self.logger=(logger)
13
+ strategy.logger = logger
14
+ end
15
+
16
+ def self.logger
17
+ strategy.logger
18
+ end
19
+
20
+ def self.strategy
21
+ Strategy.for_queue
22
+ end
11
23
  end
@@ -1,3 +1,3 @@
1
1
  module FastlyNsq
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -2,17 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe FakeMessageQueue do
4
4
  describe '@@queue' do
5
- it 'is initalized as an empty Ruby Queue' do
6
- queue = FakeMessageQueue.queue
5
+ it 'is initalized as an empty array' do
6
+ expect(FakeMessageQueue.queue).to eq []
7
+ end
8
+ end
7
9
 
8
- expect(queue).to be_a Thread::Queue
9
- expect(queue).to be_empty
10
+ describe '@@logger' do
11
+ after do
12
+ FakeMessageQueue.logger = Logger.new(nil)
13
+ end
14
+
15
+ it 'is initalized as an empty Ruby Logger' do
16
+ expect(FakeMessageQueue.logger).to be_a Logger
17
+ end
18
+
19
+ it 'can be set and retrieved' do
20
+ logger = double('some logger')
21
+ FakeMessageQueue.logger = logger
22
+
23
+ expect(FakeMessageQueue.logger).to eq logger
10
24
  end
11
25
  end
12
26
 
13
27
  describe '.reset!' do
14
28
  it 'resets the fake message queue' do
15
- FakeMessageQueue.queue.push('hello')
29
+ FakeMessageQueue.queue = ['hello']
16
30
  expect(FakeMessageQueue.queue.size).to eq 1
17
31
 
18
32
  FakeMessageQueue.reset!
@@ -42,8 +56,9 @@ RSpec.describe FakeMessageQueue::Producer do
42
56
  end
43
57
 
44
58
  describe '#terminate' do
45
- it 'has a terminate method which is a noop' do
59
+ it 'has a `terminate` method which is a noop' do
46
60
  producer = instance_double('FakeMessageQueue::Producer')
61
+
47
62
  allow(producer).to receive(:terminate)
48
63
  end
49
64
  end
@@ -79,7 +94,7 @@ RSpec.describe FakeMessageQueue::Consumer do
79
94
 
80
95
  describe '#size' do
81
96
  it 'tells you how many messages are in the queue' do
82
- FakeMessageQueue.queue.push('hello')
97
+ FakeMessageQueue.queue = ['hello']
83
98
  topic = 'death_star'
84
99
  channel = 'star_killer_base'
85
100
 
@@ -98,7 +113,7 @@ RSpec.describe FakeMessageQueue::Consumer do
98
113
  context 'when there is a message on the queue' do
99
114
  it 'returns the last message off of the queue' do
100
115
  message = FakeMessageQueue::Message.new('hello')
101
- FakeMessageQueue.queue.push(message)
116
+ FakeMessageQueue.queue = [message]
102
117
  topic = 'death_star'
103
118
  channel = 'star_killer_base'
104
119
 
@@ -114,10 +129,11 @@ RSpec.describe FakeMessageQueue::Consumer do
114
129
  end
115
130
 
116
131
  context 'when there no message on the queue' do
117
- it 'blocks on the process, waiting for a message ' do
118
- FakeMessageQueue.reset!
132
+ it 'blocks for longer than the queue check cycle' do
133
+ FakeMessageQueue.queue = []
119
134
  topic = 'death_star'
120
135
  channel = 'star_killer_base'
136
+ delay = FakeMessageQueue::Consumer::SECONDS_BETWEEN_QUEUE_CHECKS + 0.1
121
137
 
122
138
  consumer = FakeMessageQueue::Consumer.new(
123
139
  nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
@@ -126,7 +142,7 @@ RSpec.describe FakeMessageQueue::Consumer do
126
142
  )
127
143
 
128
144
  expect {
129
- Timeout::timeout(0.1) do
145
+ Timeout::timeout(delay) do
130
146
  consumer.pop
131
147
  end
132
148
  }.to raise_error(Timeout::Error)
@@ -51,20 +51,18 @@ RSpec.describe MessageQueue::Listener do
51
51
  expect(message).to have_received(:finish)
52
52
  end
53
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'
54
+ context 'when using the fake queue and it is empty', fake_queue: true do
55
+ it 'blocks on the process for longer than the check cycle' do
56
+ topic = 'testing_topic'
57
+ channel = 'testing_channel'
58
+ delay = FakeMessageQueue::Consumer::SECONDS_BETWEEN_QUEUE_CHECKS + 0.1
60
59
 
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
60
+ expect {
61
+ Timeout::timeout(delay) do
62
+ MessageQueue::Listener.new(topic: topic, channel: channel).
63
+ process_next_message
64
+ end
65
+ }.to raise_error(Timeout::Error)
68
66
  end
69
67
  end
70
68
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe MessageQueue do
4
+ describe '.logger' do
5
+ describe 'when using the fake queue' do
6
+ it 'allows the logger to be set and retrieved' do
7
+ use_fake_connection do
8
+ logger = Logger.new(STDOUT)
9
+ MessageQueue.logger = logger
10
+
11
+ expect(MessageQueue.logger).to eq logger
12
+ end
13
+ end
14
+ end
15
+
16
+ describe 'when using the real queue' do
17
+ it 'allows the logger to be set and retrieved' do
18
+ use_real_connection do
19
+ logger = Logger.new(STDOUT)
20
+ MessageQueue.logger = logger
21
+
22
+ expect(MessageQueue.logger).to eq logger
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,35 +1,40 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
  require 'fastly_nsq/rake_task'
3
3
 
4
- describe MessageQueue::RakeTask do
4
+ RSpec.describe MessageQueue::RakeTask do
5
5
  before(:each) do
6
6
  Rake::Task['begin_listening'].clear if Rake::Task.task_defined?('begin_listening')
7
7
  end
8
8
 
9
- describe 'defining tasks' do
9
+ describe 'when defining tasks' do
10
10
  it 'creates a begin_listening task' do
11
11
  MessageQueue::RakeTask.new
12
12
 
13
13
  allow_any_instance_of(MessageQueue::RakeTask).to receive(:output) { nil }
14
- assert_equal true, Rake::Task.task_defined?(:begin_listening)
14
+
15
+ is_defined = Rake::Task.task_defined?(:begin_listening)
16
+ expect(is_defined).to be_truthy
15
17
  end
16
18
 
17
19
  it 'creates a named task' do
18
20
  MessageQueue::RakeTask.new(:test_name)
19
21
 
20
22
  allow_any_instance_of(MessageQueue::RakeTask).to receive(:output) { nil }
21
- assert_equal true, Rake::Task.task_defined?(:test_name)
23
+
24
+ is_defined = Rake::Task.task_defined?(:test_name)
25
+ expect(is_defined).to be_truthy
22
26
  end
23
27
  end
24
28
 
25
- describe 'running tasks' do
29
+ describe 'when running tasks' do
26
30
  it 'runs with inline options defined' do
27
- MessageQueue::RakeTask.new(:begin_listening, [:topic, :channel])
31
+ options = { topic: 'dwarf', channel: 'star' }
32
+ task = MessageQueue::RakeTask.new(:begin_listening, [:topic, :channel])
28
33
 
29
- dbl = double('go', go: nil)
34
+ message_queue_listener = double('go', go: nil)
30
35
  expect(MessageQueue::Listener).to receive(:new).
31
- with(topic: 'dwarf', channel: 'star').
32
- and_return(dbl)
36
+ with(options).
37
+ and_return(message_queue_listener)
33
38
 
34
39
  allow_any_instance_of(MessageQueue::RakeTask).to receive(:output) { nil }
35
40
  Rake::Task['begin_listening'].execute(topic: 'dwarf', channel: 'star')
@@ -41,25 +46,25 @@ describe MessageQueue::RakeTask do
41
46
  task.channel = 'star'
42
47
  end
43
48
 
44
- dbl = double('go', go: nil)
49
+ message_queue_listener = double('go', go: nil)
45
50
  expect(MessageQueue::Listener).to receive(:new).
46
51
  with(topic: 'dwarf', channel: 'star').
47
- and_return(dbl)
52
+ and_return(message_queue_listener)
48
53
 
49
54
  allow_any_instance_of(MessageQueue::RakeTask).to receive(:output) { nil }
50
55
  Rake::Task['begin_listening'].execute(topic: 'dwarf', channel: 'star')
51
56
  end
52
57
 
53
- it 'uses inline over block' do
58
+ it 'uses inline definitions over block assignments' do
54
59
  MessageQueue::RakeTask.new(:begin_listening, [:topic, :channel]) do |task|
55
60
  task.topic = 'loud'
56
61
  task.channel = 'noise'
57
62
  end
58
63
 
59
- dbl = double('go', go: nil)
64
+ message_queue_listener = double('go', go: nil)
60
65
  expect(MessageQueue::Listener).to receive(:new).
61
66
  with(topic: 'dwarf', channel: 'star').
62
- and_return(dbl)
67
+ and_return(message_queue_listener)
63
68
 
64
69
  allow_any_instance_of(MessageQueue::RakeTask).to receive(:output) { nil }
65
70
  Rake::Task['begin_listening'].execute(topic: 'dwarf', channel: 'star')
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.2
4
+ version: 0.2.3
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-03-10 00:00:00.000000000 Z
12
+ date: 2016-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
@@ -150,6 +150,7 @@ extensions: []
150
150
  extra_rdoc_files: []
151
151
  files:
152
152
  - ".document"
153
+ - ".github/PULL_REQUEST_TEMPLATE.md"
153
154
  - ".gitignore"
154
155
  - ".rdoc_options"
155
156
  - ".ruby-version"
@@ -179,10 +180,11 @@ files:
179
180
  - spec/lib/fastly_nsq/message_queue/listener_spec.rb
180
181
  - spec/lib/fastly_nsq/message_queue/producer_spec.rb
181
182
  - spec/lib/fastly_nsq/message_queue/strategy_spec.rb
183
+ - spec/lib/fastly_nsq/message_queue_spec.rb
184
+ - spec/lib/fastly_nsq/rake_task_spec.rb
182
185
  - spec/lib/fastly_nsq/sample_message_processor_spec.rb
183
186
  - spec/spec_helper.rb
184
187
  - spec/support/env_helpers.rb
185
- - test/lib/fastly_nsq/rake_task_test.rb
186
188
  homepage: https://github.com/fastly/fastly-nsq
187
189
  licenses:
188
190
  - MIT
@@ -207,5 +209,4 @@ rubygems_version: 2.5.1
207
209
  signing_key:
208
210
  specification_version: 4
209
211
  summary: Fastly NSQ Adapter
210
- test_files:
211
- - test/lib/fastly_nsq/rake_task_test.rb
212
+ test_files: []