Skip to content

Commit 5f4e6b4

Browse files
Fix failover logic
1 parent 8e3f065 commit 5f4e6b4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

etcd3/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def channel(self):
274274
# We're failing over. We get the first non-failed channel
275275
# we encounter, and use it by calling this function again,
276276
# recursively
277-
for label, endpoint in self.endpoints:
277+
for label, endpoint in self.endpoints.items():
278278
if endpoint.is_failed():
279279
continue
280280
self._current_endpoint_label = label

tests/test_etcd3.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,19 @@ def test_connection_timeout_exception_on_connection_timeout(self, etcd):
909909
etcd.get("foo")
910910
assert etcd.endpoint_in_use.is_failed()
911911

912+
def test_single_endpoint_failover(self, etcd):
913+
etcd.failover = True
914+
exception = self.MockedException(grpc.StatusCode.UNAVAILABLE)
915+
kv_mock = mock.PropertyMock()
916+
kv_mock.Range.side_effect = exception
917+
with mock.patch('etcd3.Etcd3Client.kvstub',
918+
new_callable=mock.PropertyMock) as property_mock:
919+
property_mock.return_value = kv_mock
920+
with pytest.raises(etcd3.exceptions.ConnectionFailedError):
921+
etcd.get("foo")
922+
with pytest.raises(etcd3.exceptions.NoServerAvailableError):
923+
etcd.get("foo")
924+
912925
def test_grpc_exception_on_unknown_code(self, etcd):
913926
exception = self.MockedException(grpc.StatusCode.DATA_LOSS)
914927
kv_mock = mock.PropertyMock()

0 commit comments

Comments
 (0)