-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[network] move 'core/test_service_checks' tests
Add tests for `instance_name` tag normalization. Move 'core/test_service_checks.py' tests to 'checks/integration/test_http_check.py' and 'checks/integration/test_tcp_check.py'.
- Loading branch information
Showing
3 changed files
with
193 additions
and
193 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# stdlibb | ||
import time | ||
|
||
# project | ||
from tests.checks.common import AgentCheckTest | ||
|
||
RESULTS_TIMEOUT = 5 | ||
|
||
CONFIG = { | ||
'init_config': {}, | ||
'instances': [{ | ||
'host': '127.0.0.1', | ||
'port': 65530, | ||
'timeout': 1, | ||
'name': 'DownService' | ||
}, { | ||
'host': '126.0.0.1', | ||
'port': 65530, | ||
'timeout': 1, | ||
'name': 'DownService2' | ||
}, { | ||
'host': 'datadoghq.com', | ||
'port': 80, | ||
'timeout': 1, | ||
'name': 'UpService' | ||
}] | ||
} | ||
|
||
|
||
class TCPCheckTest(AgentCheckTest): | ||
CHECK_NAME = 'tcp_check' | ||
|
||
def tearDown(self): | ||
self.check.stop() | ||
|
||
def wait_for_async(self, method, attribute, count): | ||
""" | ||
Loop on `self.check.method` until `self.check.attribute >= count`. | ||
Raise after | ||
""" | ||
i = 0 | ||
while i < RESULTS_TIMEOUT: | ||
self.check._process_results() | ||
if len(getattr(self.check, attribute)) >= count: | ||
return getattr(self.check, method)() | ||
time.sleep(1) | ||
i += 1 | ||
raise Exception("Didn't get the right count of service checks in time {0}" | ||
.format(getattr(self.check, attribute))) | ||
|
||
def test_event_deprecation(self): | ||
""" | ||
Deprecate events usage for service checks. | ||
""" | ||
# Run the check | ||
self.run_check(CONFIG) | ||
|
||
# Overrides self.service_checks attribute when values are available | ||
self.warnings = self.wait_for_async('get_warnings', 'warnings', 3) | ||
|
||
# Assess warnings | ||
self.assertWarning( | ||
"Using events for service checks is deprecated in " | ||
"favor of monitors and will be removed in future versions of the " | ||
"Datadog Agent.", | ||
count=3 | ||
) | ||
|
||
def test_check(self): | ||
""" | ||
Check coverage. | ||
""" | ||
# Run the check | ||
self.run_check(CONFIG) | ||
|
||
# Overrides self.service_checks attribute when values are available | ||
self.service_checks = self.wait_for_async('get_service_checks', 'service_checks', 3) | ||
|
||
expected_tags = ["instance:DownService", "target_host:127.0.0.1", "port:65530"] | ||
self.assertServiceCheckCritical("tcp.can_connect", tags=expected_tags) | ||
|
||
expected_tags = ["instance:DownService2", "target_host:126.0.0.1", "port:65530"] | ||
self.assertServiceCheckCritical("tcp.can_connect", tags=expected_tags) | ||
|
||
expected_tags = ["instance:UpService", "target_host:datadoghq.com", "port:80"] | ||
self.assertServiceCheckOK("tcp.can_connect", tags=expected_tags) | ||
|
||
self.coverage_report() |
Oops, something went wrong.