Skip to content

Commit

Permalink
test: ensure sane logging levels
Browse files Browse the repository at this point in the history
in --release mode fail tests w/ excessive logging levels (unless
explicitly stated w/ @max_logs)

Closes #117
  • Loading branch information
pjenvey committed Feb 14, 2020
1 parent ea2eb61 commit d6beb4c
Showing 1 changed file with 24 additions and 53 deletions.
77 changes: 24 additions & 53 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ def get_free_port():

def enqueue_output(out, queue):
for line in iter(out.readline, b''):
print('ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ')
queue.put(line)
out.close()


#def ensure_sane_logs(endpoint_logs, endpoint_log_counts, cn_queues, cn_log_counts):
#def ensure_sane_logs(testcase):
def process_logs(testcase):
"""Process (print) the testcase logs (in tearDown).
Ensures a maximum level of logs allowed to be emitted when running
w/ a `--release` mode connection node
"""
conn_count = sum(queue.qsize() for queue in CN_QUEUES)

for queue in CN_QUEUES:
Expand All @@ -111,31 +114,34 @@ def process_logs(testcase):
else:
print(line)

print 'ZZZZZZZZZZZZZZZZZZZZ %s %s' % (testcase.max_endpoint_logs, testcase.max_conn_logs)
if not STRICT_LOG_COUNTS:
return

MSG = "endpoint node emitted excessive log statements, count: {} > max: {}"
endpoint_count = len(testcase.logs)
print 'WHAT %s %s %s' % (endpoint_count <= testcase.max_endpoint_logs, endpoint_count, testcase.max_endpoint_logs)
# Give an extra to endpoint for potential startup log messages
# (e.g. when running tests individually)
max_endpoint_logs = testcase.max_endpoint_logs + 1
assert endpoint_count <= max_endpoint_logs, MSG.format(
endpoint_count, max_endpoint_logs)

MSG = "conn node emitted excessive log statements, count: {} > max: {}"
print '+ZZZ %s %s' % (conn_count, sum(queue.qsize() for queue in CN_QUEUES))
assert conn_count <= testcase.max_conn_logs, MSG.format(conn_count, testcase.max_conn_logs)
assert conn_count <= testcase.max_conn_logs, MSG.format(
conn_count, testcase.max_conn_logs)


def max_logs(endpoint=None, conn=None):
"""Adjust max_endpoint/conn_logs values for individual test cases.
They're utilized by the process_logs function
"""
def max_logs_decorator(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
if endpoint is not None:
print('ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ %s' % self)
orig_max_endpoint_logs = self.max_endpoint_logs
self.max_endpoint_logs = endpoint
if conn is not None:
orig_max_conn_logs = self.max_conn_logs
self.max_conn_logs = conn
return func(self, *args, **kwargs)
return wrapper
Expand Down Expand Up @@ -164,7 +170,8 @@ def send_bad_data(self):


def setup_module():
global CN_SERVER, CN_QUEUES, CN_MP_SERVER, MOCK_SERVER_THREAD, STRICT_LOG_COUNTS
global CN_SERVER, CN_QUEUES, CN_MP_SERVER, MOCK_SERVER_THREAD, \
STRICT_LOG_COUNTS
ap_tests.ddb_jar = os.path.join(root_dir, "ddb", "DynamoDBLocal.jar")
ap_tests.ddb_lib_dir = os.path.join(root_dir, "ddb", "DynamoDBLocal_lib")
ap_tests.setUp()
Expand All @@ -190,15 +197,17 @@ def setup_module():
human_logs="true",
msg_limit=MSG_LIMIT,
)
# XXX: if release, can adjust logging level check
rust_bin = root_dir + "/target/release/autopush_rs"
#rust_bin = root_dir + "/target/debug/autopush_rs"
possible_paths = ["/target/debug/autopush_rs",
"/autopush_rs/target/release/autopush_rs",
"/autopush_rs/target/debug/autopush_rs"]
while possible_paths and not os.path.exists(rust_bin): # pragma: nocover
rust_bin = root_dir + possible_paths.pop(0)

if 'release' not in rust_bin:
# disable checks for chatty debug mode autopush-rs
STRICT_LOG_COUNTS = False

# Setup the environment
for key, val in conn_conf.items():
key = "autopush_" + key
Expand Down Expand Up @@ -315,20 +324,8 @@ def setUp(self):

def tearDown(self):
process_logs(self)
"""
for queue in CN_QUEUES:
is_empty = False
while not is_empty:
try:
line = queue.get_nowait()
except Empty:
is_empty = True
else:
print(line)
"""
while not MOCK_SENTRY_QUEUE.empty():
MOCK_SENTRY_QUEUE.get_nowait()
#ensure_sane_logs(self.logs, self.max_endpoint_logs, CN_QUEUES, self.max_conn_logs)

def endpoint_kwargs(self):
return self._endpoint_defaults
Expand Down Expand Up @@ -597,7 +594,6 @@ def test_multiple_delivery_repeat_without_ack(self):
yield self.shut_down(client)

@inlineCallbacks
@max_logs(conn=4)
def test_multiple_legacy_delivery_with_single_ack(self):
data = str(uuid.uuid4())
data2 = str(uuid.uuid4())
Expand Down Expand Up @@ -646,6 +642,7 @@ def test_topic_expired(self):
yield self.shut_down(client)

@inlineCallbacks
@max_logs(conn=4)
def test_multiple_delivery_with_single_ack(self):
data = str(uuid.uuid4())
data2 = str(uuid.uuid4())
Expand Down Expand Up @@ -1045,18 +1042,6 @@ def setUp(self):

def tearDown(self):
process_logs(self)
"""
ensure_sane_logs(self)
for queue in CN_QUEUES:
is_empty = False
while not is_empty:
try:
line = queue.get_nowait()
except Empty:
is_empty = True
else:
print(line)
"""

def endpoint_kwargs(self):
return self._endpoint_defaults
Expand Down Expand Up @@ -1471,8 +1456,7 @@ def test_webpush_monthly_rotation_old_user_dropped(self):
client.uaid,
old_month
)
old_message = Message(old_month,
boto_resource=autopush.tests.boto_resource)
_ = Message(old_month, boto_resource=autopush.tests.boto_resource)

# Verify the move
c = yield deferToThread(self.conn.db.router.get_uaid, client.uaid)
Expand Down Expand Up @@ -1553,19 +1537,6 @@ def setUp(self):

def tearDown(self):
process_logs(self)
"""
ensure_sane_logs(self)
for queue in CN_QUEUES:
is_empty = False
while not is_empty:
try:
line = queue.get_nowait()
except Empty:
is_empty = True
else:
print(line)
#ensure_sane_logs(self.logs, self.max_endpoint_logs, CN_QUEUES, self.max_conn_logs)
"""

def endpoint_kwargs(self):
return self._endpoint_defaults
Expand Down

0 comments on commit d6beb4c

Please sign in to comment.