From f371fea9c369ded8539129e0647d525364e7d2bb Mon Sep 17 00:00:00 2001 From: Soulou Date: Fri, 18 Jan 2019 15:11:08 +0100 Subject: [PATCH] Add specs for synchronous producer (ensure exception is thrown) --- lib/nsq/connection.rb | 1 - spec/lib/nsq/producer_synchronous_spec.rb | 26 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 spec/lib/nsq/producer_synchronous_spec.rb diff --git a/lib/nsq/connection.rb b/lib/nsq/connection.rb index a89fe9a..01cc9b2 100644 --- a/lib/nsq/connection.rb +++ b/lib/nsq/connection.rb @@ -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) diff --git a/spec/lib/nsq/producer_synchronous_spec.rb b/spec/lib/nsq/producer_synchronous_spec.rb new file mode 100644 index 0000000..1a0106d --- /dev/null +++ b/spec/lib/nsq/producer_synchronous_spec.rb @@ -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