Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse timeouts as floats in RequestsWrapper #3448

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datadog_checks_base/datadog_checks/base/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, instance, init_config, remapper=None):
config[field] = value

# http://docs.python-requests.org/en/master/user/advanced/#timeouts
timeout = int(config['timeout'])
timeout = float(config['timeout'])

# http://docs.python-requests.org/en/master/user/quickstart/#custom-headers
# http://docs.python-requests.org/en/master/user/advanced/#header-ordering
Expand Down
26 changes: 7 additions & 19 deletions datadog_checks_base/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,36 @@
pytestmark = pytest.mark.http


def test_default_timeout():
# Assert the timeout is slightly larger than a multiple of 3,
# which is the default TCP packet retransmission window. See:
# https://tools.ietf.org/html/rfc2988
assert 0 < STANDARD_FIELDS['timeout'] % 3 <= 1


class TestAttribute:
def test_default(self):
check = AgentCheck('test', {}, [{}])

assert check._http is None

def test_flag(self):
def test_activate(self):
check = AgentCheck('test', {}, [{}])

assert check.http == check._http
assert isinstance(check.http, RequestsWrapper)

def test_remapper_no_trigger(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this test was not necessary before the change

class TestCheck(AgentCheck):
HTTP_CONFIG_REMAPPER = {'foo': {}}

check = TestCheck('test', {}, [{}])

assert check._http is None


class TestTimeout:
def test_config_default(self):
instance = {}
init_config = {}
http = RequestsWrapper(instance, init_config)

assert http.options['timeout'] == STANDARD_FIELDS['timeout']
# Assert the timeout is slightly larger than a multiple of 3,
# which is the default TCP packet retransmission window. See:
# https://tools.ietf.org/html/rfc2988
assert 0 < http.options['timeout'] % 3 <= 1

def test_config_timeout(self):
instance = {'timeout': 25}
instance = {'timeout': 24.5}
init_config = {}
http = RequestsWrapper(instance, init_config)

assert http.options['timeout'] == 25
assert http.options['timeout'] == 24.5


class TestHeaders:
Expand Down