1
1
import cPickle as pickle
2
2
from mock import patch , MagicMock , sentinel , create_autospec , Mock , call
3
3
import pytest
4
- from pymongo .errors import OperationFailure
4
+ from pymongo .errors import OperationFailure , ServerSelectionTimeoutError , AutoReconnect
5
5
from pymongo .mongo_client import MongoClient
6
6
7
7
from arctic .auth import Credential
@@ -77,10 +77,10 @@ def test_arctic_connect_hostname():
77
77
serverSelectionTimeoutMS = sentinel .select_timeout )
78
78
# do something to trigger lazy arctic init
79
79
store .list_libraries ()
80
- ar ( mc ) .assert_called_once_with (host = gmu ('hostname' ), maxPoolSize = 4 ,
81
- socketTimeoutMS = sentinel .socket_timeout ,
82
- connectTimeoutMS = sentinel .connect_timeout ,
83
- serverSelectionTimeoutMS = sentinel .select_timeout )
80
+ mc .assert_called_once_with (host = gmu ('hostname' ), maxPoolSize = 4 ,
81
+ socketTimeoutMS = sentinel .socket_timeout ,
82
+ connectTimeoutMS = sentinel .connect_timeout ,
83
+ serverSelectionTimeoutMS = sentinel .select_timeout )
84
84
85
85
86
86
def test_arctic_connect_with_environment_name ():
@@ -94,10 +94,10 @@ def test_arctic_connect_with_environment_name():
94
94
# do something to trigger lazy arctic init
95
95
store .list_libraries ()
96
96
assert gmfe .call_args_list == [call ('live' )]
97
- assert ar ( mc ) .call_args_list == [call (host = gmfe .return_value , maxPoolSize = 4 ,
98
- socketTimeoutMS = sentinel .socket_timeout ,
99
- connectTimeoutMS = sentinel .connect_timeout ,
100
- serverSelectionTimeoutMS = sentinel .select_timeout )]
97
+ assert mc .call_args_list == [call (host = gmfe .return_value , maxPoolSize = 4 ,
98
+ socketTimeoutMS = sentinel .socket_timeout ,
99
+ connectTimeoutMS = sentinel .connect_timeout ,
100
+ serverSelectionTimeoutMS = sentinel .select_timeout )]
101
101
102
102
103
103
@pytest .mark .parametrize (
@@ -336,3 +336,22 @@ def test_arctic_set_get_state():
336
336
assert mnew ._socket_timeout == 1234
337
337
assert mnew ._connect_timeout == 2345
338
338
assert mnew ._server_selection_timeout == 3456
339
+
340
+
341
+ def test__conn_auth_issue ():
342
+ auth_timeout = [0 ]
343
+
344
+ a = Arctic ("host:12345" )
345
+ sentinel .creds = Mock ()
346
+
347
+ def flaky_auth (* args , ** kwargs ):
348
+ if not auth_timeout [0 ]:
349
+ auth_timeout [0 ] = 1
350
+ raise AutoReconnect ()
351
+
352
+ with patch ('arctic.arctic.authenticate' , flaky_auth ), \
353
+ patch ('arctic.arctic.get_auth' , return_value = sentinel .creds ), \
354
+ patch ('arctic.decorators._handle_error' ) as he :
355
+ a ._conn
356
+ assert he .call_count == 1
357
+ assert auth_timeout [0 ]
0 commit comments