]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
test: Make log detection sensitive to info logs 2083/head
authorBen Darnell <ben@bendarnell.com>
Sun, 11 Jun 2017 03:00:08 +0000 (23:00 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 11 Jun 2017 03:00:08 +0000 (23:00 -0400)
Silence one in httpserver_test

tornado/test/httpserver_test.py
tornado/test/runtests.py

index a3b86ac99aba81f0fc96cafbc4748ce505556472..4444a39220a5812b3772f2745da78b57ae89ea22 100644 (file)
@@ -408,12 +408,13 @@ class HTTPServerRawTest(AsyncHTTPTestCase):
         self.wait()
 
     def test_malformed_first_line_response(self):
-        self.stream.write(b'asdf\r\n\r\n')
-        read_stream_body(self.stream, self.stop)
-        start_line, headers, response = self.wait()
-        self.assertEqual('HTTP/1.1', start_line.version)
-        self.assertEqual(400, start_line.code)
-        self.assertEqual('Bad Request', start_line.reason)
+        with ExpectLog(gen_log, '.*Malformed HTTP request line'):
+            self.stream.write(b'asdf\r\n\r\n')
+            read_stream_body(self.stream, self.stop)
+            start_line, headers, response = self.wait()
+            self.assertEqual('HTTP/1.1', start_line.version)
+            self.assertEqual(400, start_line.code)
+            self.assertEqual('Bad Request', start_line.reason)
 
     def test_malformed_first_line_log(self):
         with ExpectLog(gen_log, '.*Malformed HTTP request line'):
index b81c5f225ebdbcbbe6aa888c75611c663880c533..dc702eda48b16c0ccf277cc46e47739924ac22ce 100644 (file)
@@ -80,13 +80,15 @@ class LogCounter(logging.Filter):
     def __init__(self, *args, **kwargs):
         # Can't use super() because logging.Filter is an old-style class in py26
         logging.Filter.__init__(self, *args, **kwargs)
-        self.warning_count = self.error_count = 0
+        self.info_count = self.warning_count = self.error_count = 0
 
     def filter(self, record):
         if record.levelno >= logging.ERROR:
             self.error_count += 1
         elif record.levelno >= logging.WARNING:
             self.warning_count += 1
+        elif record.levelno >= logging.INFO:
+            self.info_count += 1
         return True
 
 
@@ -177,12 +179,15 @@ def main():
     try:
         tornado.testing.main(**kwargs)
     finally:
-        # The tests should run clean; consider it a failure if they logged
-        # any warnings or errors. We'd like to ban info logs too, but
-        # we can't count them cleanly due to interactions with LogTrapTestCase.
-        if log_counter.warning_count > 0 or log_counter.error_count > 0:
-            logging.error("logged %d warnings and %d errors",
-                          log_counter.warning_count, log_counter.error_count)
+        # The tests should run clean; consider it a failure if they
+        # logged anything at info level or above (except for the one
+        # allowed info message "PASS")
+        if (log_counter.info_count > 1 or
+            log_counter.warning_count > 0 or
+            log_counter.error_count > 0):
+            logging.error("logged %d infos, %d warnings, and %d errors",
+                          log_counter.info_count, log_counter.warning_count,
+                          log_counter.error_count)
             sys.exit(1)