Skip to content

Commit

Permalink
Add specs for synchronous producer (ensure exception is thrown)
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulou committed Jan 18, 2019
1 parent 308dfd7 commit f371fea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/nsq/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def handle_response(frame)

def receive_frame
if buffer = @socket.read(8)
raise EOFError if buffer.length == 0
size, type = buffer.unpack('l>l>')
size -= 4 # we want the size of the data part and type already took up 4 bytes
data = @socket.read(size)
Expand Down
26 changes: 26 additions & 0 deletions spec/lib/nsq/producer_synchronous_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative '../../spec_helper'

describe Nsq::Producer do
context 'with a synchronous producer' do
before do
@cluster = NsqCluster.new(nsqd_count: 1)
@nsqd = @cluster.nsqd.first
@producer = new_producer(@nsqd, synchronous: true)
end

after do
@producer.terminate if @producer
@cluster.destroy
end

describe '#write' do
it 'shouldn\'t raise an error when nsqd is down' do
@nsqd.stop

expect{
@producer.write('fail')
}.to raise_error(RuntimeError, "No data from socket")
end
end
end
end

0 comments on commit f371fea

Please sign in to comment.