-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Overseas-Student-Living/connection_error_d…
…iscards ConnectionError discards client from pool
- Loading branch information
Showing
4 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from eventlet.event import Event | ||
from mock import patch | ||
import pytest | ||
import requests | ||
import requests_mock | ||
from simple_salesforce import SalesforceResourceNotFound | ||
|
||
|
@@ -156,6 +157,39 @@ def test_bad_clients_are_discarded(client, mock_salesforce_server): | |
assert len(client.pool.free) == 1 | ||
|
||
|
||
@pytest.mark.usefixtures('fast_retry') | ||
def test_bad_connections_are_discarded(client, mock_salesforce_server): | ||
|
||
# first call is successful; second is ConnectionError | ||
requests_data = {'LastName': 'Smith', 'Email': '[email protected]'} | ||
response_data = { | ||
'errors': [], | ||
'id': '003e0000003GuNXAA0', | ||
'success': True | ||
} | ||
mock_salesforce_server.post( | ||
requests_mock.ANY, | ||
[ | ||
{'json': response_data}, | ||
{'exc': requests.exceptions.ConnectionError} | ||
] | ||
) | ||
|
||
assert client.Contact.create(requests_data) == response_data | ||
|
||
assert len(client.pool.busy) == 0 | ||
assert len(client.pool.free) == 1 | ||
_first_client = list(client.pool.free)[0] | ||
|
||
with pytest.raises(requests.exceptions.ConnectionError): | ||
client.Contact.create(requests_data) | ||
|
||
# first client is discarded from the pool | ||
assert _first_client not in client.pool.free | ||
assert len(client.pool.busy) == 0 | ||
assert len(client.pool.free) == 0 | ||
|
||
|
||
@pytest.mark.usefixtures('fast_retry') | ||
def test_proxy_retries_on_session_expired(client, mock_salesforce_server): | ||
|
||
|