Skip to content

Commit

Permalink
Merge cec7f0a into 55125a6
Browse files Browse the repository at this point in the history
  • Loading branch information
amiel committed Oct 20, 2017
2 parents 55125a6 + cec7f0a commit 19abb98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/neo4j/core/cypher_session/adaptors/bolt.rb
Expand Up @@ -185,7 +185,7 @@ def sendmsg(message)
@socket.send(message, 0)
end

def recvmsg(size, timeout = 10)
def recvmsg(size, timeout = timeout_option)
Timeout.timeout(timeout) do
@socket.recv(size).tap do |result|
log_message :S, result
Expand Down Expand Up @@ -228,6 +228,10 @@ def flush_response
[].tap { |r| while arg = unpacker.unpack_value!; r << arg; end }
end

def timeout_option
@options.fetch(:timeout) { 10 }
end

# Represents messages sent to or received from the server
class Message
TYPE_CODES = {
Expand Down
16 changes: 16 additions & 0 deletions spec/neo4j/core/cypher_session/adaptors/bolt_spec.rb
Expand Up @@ -58,4 +58,20 @@

it_behaves_like 'Neo4j::Core::CypherSession::Adaptor'
end

describe 'timeouts' do
it 'defaults to 10' do
expect(Timeout).to receive(:timeout).with(10)
adaptor.send(:recvmsg, 1)
end

context 'when a timeout is configured' do
let(:adaptor) { adaptor_class.new(url, timeout: 20) }

it 'uses the configured timeout' do
expect(Timeout).to receive(:timeout).with(20)
adaptor.send(:recvmsg, 1)
end
end
end
end

0 comments on commit 19abb98

Please sign in to comment.