Skip to content

Commit

Permalink
do not close client connection when 50x error is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudum committed Aug 28, 2014
1 parent f57f0fc commit 08260e5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -2,6 +2,8 @@
Changes for crate
=================

- more reliable failover mechanism

2014/08/26 0.11.0
=================

Expand Down
3 changes: 2 additions & 1 deletion src/crate/client/http.py
Expand Up @@ -292,7 +292,8 @@ def _request(self, method, path, server=None, **kwargs):
with self._lock:
# drop server from active ones
self._drop_server(next_server, response.reason)
return response
else:
return response
except (urllib3.exceptions.MaxRetryError,
urllib3.exceptions.ReadTimeoutError,
urllib3.exceptions.SSLError,
Expand Down
10 changes: 6 additions & 4 deletions src/crate/client/test_http.py
Expand Up @@ -102,8 +102,9 @@ def reason(self):
return self._reason

def request(self, method, path, data=None, stream=False, **kwargs):
self._reason = self.REASONS[self.counter%2]
self._status = self.STATI[self.counter%2]
self._reason = self.REASONS[self.counter % len(self.REASONS)]
self._status = self.STATI[self.counter % len(self.STATI)]
print(self.counter, self._status)
self.counter += 1
mock_response = MagicMock()
mock_response.status = self._status
Expand Down Expand Up @@ -195,10 +196,11 @@ def test_programming_error_contains_http_error_response_content(self):

@patch('crate.client.http.Server', FakeServer50xResponse)
def test_server_error_50x(self):
client = Client(servers="localhost:4200")
client = Client(servers="localhost:4200 localhost:4201")
client.sql('select 1')
client.sql('select 2')
try:
client.sql('select 2')
client.sql('select 3')
except ProgrammingError as e:
self.assertEqual("No more Servers available, exception from last server: Service Unavailable",
e.message)
Expand Down

0 comments on commit 08260e5

Please sign in to comment.