Skip to content

Commit

Permalink
Some more tests, try to improve Python 2.6 tests and try to fix #1007
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Mar 24, 2018
1 parent 5691386 commit 5688a91
Showing 1 changed file with 94 additions and 35 deletions.
129 changes: 94 additions & 35 deletions test/test_statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,29 @@ def test_statsmgr_register_enabled(self):
assert self.statsmgr.broks_enabled is False
assert self.statsmgr.statsd_sock is not None
assert self.statsmgr.statsd_addr is not None
self.assert_log_match(re.escape(
'DEBUG: [arbiter-master.alignak.stats] StatsD configuration for arbiter-master - localhost:8125, '
'prefix: alignak, enabled: True, broks: False, file: None'
), 0)

index = 0
# Only for Python > 2.7, DEBUG logs ...
if os.sys.version_info > (2, 7):
index = 1
self.assert_log_match(re.escape(
'DEBUG: [arbiter-master.alignak.stats] StatsD configuration for arbiter-master - localhost:8125, '
'prefix: alignak, enabled: True, broks: False, file: None'
), 0)

self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Sending arbiter-master daemon statistics '
'to: localhost:8125, prefix: alignak'
), 1)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Trying to contact StatsD server...'
), 2)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] StatsD server contacted'
), 3)
), index)
index += 1

def test_statsmgr_register_enabled_broks(self):
""" Stats manager is registered as enabled and broks are enabled
Expand All @@ -172,20 +181,29 @@ def test_statsmgr_register_enabled_broks(self):
assert self.statsmgr.broks_enabled is True
assert self.statsmgr.statsd_sock is not None
assert self.statsmgr.statsd_addr is not None
self.assert_log_match(re.escape(
'DEBUG: [arbiter-master.alignak.stats] StatsD configuration for arbiter-master - localhost:8125, '
'prefix: alignak, enabled: True, broks: True, file: None'
), 0)

index = 0
# Only for Python > 2.7, DEBUG logs ...
if os.sys.version_info > (2, 7):
index = 1
self.assert_log_match(re.escape(
'DEBUG: [arbiter-master.alignak.stats] StatsD configuration for arbiter-master - localhost:8125, '
'prefix: alignak, enabled: True, broks: True, file: None'
), 0)

self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Sending arbiter-master daemon statistics '
'to: localhost:8125, prefix: alignak'
), 1)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Trying to contact StatsD server...'
), 2)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] StatsD server contacted'
), 3)
), index)
index += 1

def test_statsmgr_connect(self):
""" Test connection in disabled mode
Expand Down Expand Up @@ -213,19 +231,27 @@ def test_statsmgr_connect_port_error(self):
assert self.statsmgr.register('arbiter-master', 'arbiter',
statsd_host='localhost', statsd_port=8888,
statsd_prefix='alignak', statsd_enabled=True)
index = 0
# Only for Python > 2.7, DEBUG logs ...
if os.sys.version_info > (2, 7):
index = 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Sending arbiter-master daemon statistics '
'to: localhost:8888, prefix: alignak'
), 1)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Trying to contact StatsD server...'
), 2)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] StatsD server contacted'
), 3)
), index)
index += 1
self.assert_log_match(re.escape(
'[arbiter-master.alignak.stats] Alignak internal statistics are sent to StatsD.'
), 4)
), index)
index += 1

# "Connected" to StatsD server - even with a bad port number!
self.assert_no_log_match('Cannot create StatsD socket')
Expand All @@ -239,19 +265,27 @@ def test_statsmgr_timer(self):
statsd_host='localhost', statsd_port=8125,
statsd_prefix='alignak', statsd_enabled=True,
broks_enabled=True)
index = 0
# Only for Python > 2.7, DEBUG logs ...
if os.sys.version_info > (2, 7):
index = 1
self.show_logs()
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Sending arbiter-master daemon statistics to: localhost:8125, prefix: alignak'
), 1)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Trying to contact StatsD server...'
), 2)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] StatsD server contacted'
), 3)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Alignak internal statistics are sent to StatsD.'
), 4)
), index)
index += 1

assert self.statsmgr.stats == {}

Expand Down Expand Up @@ -327,19 +361,27 @@ def test_statsmgr_counter(self):
statsd_host='localhost', statsd_port=8125,
statsd_prefix='alignak', statsd_enabled=True,
broks_enabled=True)
index = 0
# Only for Python > 2.7, DEBUG logs ...
if os.sys.version_info > (2, 7):
index = 1
self.show_logs()
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Sending broker-master daemon statistics to: localhost:8125, prefix: alignak'
), 1)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Trying to contact StatsD server...'
), 2)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] StatsD server contacted'
), 3)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Alignak internal statistics are sent to StatsD.'
), 4)
), index)
index += 1

assert self.statsmgr.stats == {}

Expand Down Expand Up @@ -415,19 +457,27 @@ def test_statsmgr_gauge(self):
statsd_host='localhost', statsd_port=8125,
statsd_prefix='alignak', statsd_enabled=True,
broks_enabled=True)
index = 0
# Only for Python > 2.7, DEBUG logs ...
if os.sys.version_info > (2, 7):
index = 1
self.show_logs()
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Sending arbiter-master daemon statistics to: localhost:8125, prefix: alignak'
), 1)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Trying to contact StatsD server...'
), 2)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] StatsD server contacted'
), 3)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Alignak internal statistics are sent to StatsD.'
), 4)
), index)
index += 1

assert self.statsmgr.stats == {}

Expand Down Expand Up @@ -596,22 +646,31 @@ def test_statsmgr_gauge_file(self):
statsd_host='localhost', statsd_port=8125,
statsd_prefix='alignak', statsd_enabled=True,
broks_enabled=True)
index = 0
# Only for Python > 2.7, DEBUG logs ...
if os.sys.version_info > (2, 7):
index = 1
self.show_logs()
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Sending arbiter-master daemon statistics to: localhost:8125, prefix: alignak'
), 1)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Trying to contact StatsD server...'
), 2)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] StatsD server contacted'
), 3)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Alignak internal statistics are sent to StatsD.'
), 4)
), index)
index += 1
self.assert_log_match(re.escape(
'INFO: [arbiter-master.alignak.stats] Alignak internal statistics are written in the file /tmp/stats.alignak'
), 5)
), index)
index += 1

assert self.statsmgr.stats == {}

Expand Down

0 comments on commit 5688a91

Please sign in to comment.