-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix retry logic failures * changelog * add tests to make sure data is getting where it needs to * rename file * remove duplicate file
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Fixes | ||
body: Fix retry logic to return values after initial try | ||
time: 2022-04-22T13:12:27.239055-05:00 | ||
custom: | ||
Author: emmyoop | ||
Issue: "5023" | ||
PR: "5137" |
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,59 @@ | ||
import functools | ||
import pytest | ||
from requests.exceptions import RequestException | ||
from dbt.exceptions import ConnectionException | ||
from dbt.utils import _connection_exception_retry | ||
|
||
|
||
def no_retry_fn(): | ||
return "success" | ||
|
||
|
||
class TestNoRetries: | ||
def test_no_retry(self): | ||
fn_to_retry = functools.partial(no_retry_fn) | ||
result = _connection_exception_retry(fn_to_retry, 3) | ||
|
||
expected = "success" | ||
|
||
assert result == expected | ||
|
||
|
||
def no_success_fn(): | ||
raise RequestException("You'll never pass") | ||
return "failure" | ||
|
||
|
||
class TestMaxRetries: | ||
def test_no_retry(self): | ||
fn_to_retry = functools.partial(no_success_fn) | ||
|
||
with pytest.raises(ConnectionException): | ||
_connection_exception_retry(fn_to_retry, 3) | ||
|
||
|
||
def single_retry_fn(): | ||
global counter | ||
if counter == 0: | ||
counter += 1 | ||
raise RequestException("You won't pass this one time") | ||
elif counter == 1: | ||
counter += 1 | ||
return "success on 2" | ||
|
||
return "How did we get here?" | ||
|
||
|
||
class TestSingleRetry: | ||
def test_no_retry(self): | ||
global counter | ||
counter = 0 | ||
|
||
fn_to_retry = functools.partial(single_retry_fn) | ||
result = _connection_exception_retry(fn_to_retry, 3) | ||
expected = "success on 2" | ||
|
||
# We need to test the return value here, not just that it did not throw an error. | ||
# If the value is not being passed it causes cryptic errors | ||
assert result == expected | ||
assert counter == 2 |