-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retry GitHub download failures (#3729)
* Retry GitHub download failures * Refactor and add tests * Fixed linting and added comment * Fixing unit test assertRaises Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Fixing casing Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Changing to use partial for function calls Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com>
- Loading branch information
Showing
7 changed files
with
89 additions
and
36 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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import requests | ||
import unittest | ||
|
||
from dbt.exceptions import ConnectionException | ||
from dbt.utils import _connection_exception_retry as connection_exception_retry | ||
|
||
|
||
class TestCoreDbtUtils(unittest.TestCase): | ||
def test_connection_exception_retry_none(self): | ||
Counter._reset() | ||
connection_exception_retry(lambda: Counter._add(), 5) | ||
self.assertEqual(1, counter) | ||
|
||
def test_connection_exception_retry_max(self): | ||
Counter._reset() | ||
with self.assertRaises(ConnectionException): | ||
connection_exception_retry(lambda: Counter._add_with_exception(), 5) | ||
self.assertEqual(6, counter) # 6 = original attempt plus 5 retries | ||
|
||
def test_connection_exception_retry_success(self): | ||
Counter._reset() | ||
connection_exception_retry(lambda: Counter._add_with_limited_exception(), 5) | ||
self.assertEqual(2, counter) # 2 = original attempt plus 1 retry | ||
|
||
|
||
counter:int = 0 | ||
class Counter(): | ||
def _add(): | ||
global counter | ||
counter+=1 | ||
def _add_with_exception(): | ||
global counter | ||
counter+=1 | ||
raise requests.exceptions.ConnectionError | ||
def _add_with_limited_exception(): | ||
global counter | ||
counter+=1 | ||
if counter < 2: | ||
raise requests.exceptions.ConnectionError | ||
def _reset(): | ||
global counter | ||
counter = 0 |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import unittest | ||
|
||
from dbt.exceptions import RegistryException | ||
from dbt.clients.registry import _get | ||
from dbt.exceptions import ConnectionException | ||
from dbt.clients.registry import _get_with_retries | ||
|
||
class testRegistryGetRequestException(unittest.TestCase): | ||
def test_registry_request_error_catching(self): | ||
# using non routable IP to test connection error logic in the _get function | ||
self.assertRaises(RegistryException, _get, '', 'http://0.0.0.0') | ||
# using non routable IP to test connection error logic in the _get_with_retries function | ||
self.assertRaises(ConnectionException, _get_with_retries, '', 'http://0.0.0.0') |