18
18
# See the License for the specific language governing permissions and
19
19
# limitations under the License.
20
20
21
+ import logging
22
+ from unittest .mock import MagicMock
21
23
22
24
import pytest
23
25
@@ -186,7 +188,7 @@ def test_n_and_qid_extras_in_pull(fake_socket):
186
188
def test_hello_passes_routing_metadata (fake_socket_pair ):
187
189
address = ("127.0.0.1" , 7687 )
188
190
sockets = fake_socket_pair (address )
189
- sockets .server .send_message (0x70 , {"server" : "Neo4j/4.2 .0" })
191
+ sockets .server .send_message (0x70 , {"server" : "Neo4j/4.3 .0" })
190
192
connection = Bolt4x3 (address , sockets .client ,
191
193
PoolConfig .max_connection_lifetime ,
192
194
routing_context = {"foo" : "bar" })
@@ -195,3 +197,37 @@ def test_hello_passes_routing_metadata(fake_socket_pair):
195
197
assert tag == 0x01
196
198
assert len (fields ) == 1
197
199
assert fields [0 ]["routing" ] == {"foo" : "bar" }
200
+
201
+
202
+ @pytest .mark .parametrize (("recv_timeout" , "valid" ), (
203
+ (1 , True ),
204
+ (42 , True ),
205
+ (- 1 , False ),
206
+ (0 , False ),
207
+ (2.5 , False ),
208
+ (None , False ),
209
+ ("1" , False ),
210
+ ))
211
+ def test_hint_recv_timeout_seconds (fake_socket_pair , recv_timeout , valid ,
212
+ caplog ):
213
+ address = ("127.0.0.1" , 7687 )
214
+ sockets = fake_socket_pair (address )
215
+ sockets .client .settimeout = MagicMock ()
216
+ sockets .server .send_message (0x70 , {
217
+ "server" : "Neo4j/4.2.0" ,
218
+ "hints" : {"connection.recv_timeout_seconds" : recv_timeout },
219
+ })
220
+ connection = Bolt4x3 (address , sockets .client ,
221
+ PoolConfig .max_connection_lifetime )
222
+ with caplog .at_level (logging .INFO ):
223
+ connection .hello ()
224
+ invalid_value_logged = any (repr (recv_timeout ) in msg
225
+ and "recv_timeout_seconds" in msg
226
+ and "invalid" in msg
227
+ for msg in caplog .messages )
228
+ if valid :
229
+ sockets .client .settimeout .assert_called_once_with (recv_timeout )
230
+ assert not invalid_value_logged
231
+ else :
232
+ sockets .client .settimeout .assert_not_called ()
233
+ assert invalid_value_logged
0 commit comments