예제 #1
0
 def test_child_process_logging(self, tmpdir):
     log_file = self.get_logfile_path(str(tmpdir))
     openwpm_logger = mp_logger.MPLogger(log_file)
     child_process = Process(target=child_proc_logging_exception())
     child_process.daemon = True
     child_process.start()
     openwpm_logger.close()
     child_process.join()
     log_content = self.get_logfile_contents(log_file)
     assert "I'm logging an exception" in log_content
예제 #2
0
    def test_multiprocess(self, tmpdir):
        # Set up loggingserver
        log_file = self.get_logfile_path(str(tmpdir))
        openwpm_logger = mp_logger.MPLogger(log_file)

        child_process_1 = Process(target=child_proc, args=(0, ))
        child_process_1.daemon = True
        child_process_1.start()
        child_process_2 = Process(target=child_proc, args=(1, ))
        child_process_2.daemon = True
        child_process_2.start()

        # Send some sample logs
        logger.info(PARENT_INFO_STR_1)
        logger.error(PARENT_ERROR_STR)
        logger.critical(PARENT_CRITICAL_STR)
        logger.debug(PARENT_DEBUG_STR)
        logger.warning(PARENT_WARNING_STR)

        logger1 = logging.getLogger("test1")
        logger2 = logging.getLogger("test2")
        logger1.info(NAMED_LOGGER_INFO_1)
        logger2.info(NAMED_LOGGER_INFO_2)

        # Close the logging server
        time.sleep(2)  # give some time for logs to be sent
        openwpm_logger.close()
        child_process_1.join()
        child_process_2.join()
        print("Child processes joined...")

        log_content = self.get_logfile_contents(log_file)
        for child in range(2):
            assert log_content.count(CHILD_INFO_STR_1 % child) == 1
            assert log_content.count(CHILD_INFO_STR_2 % child) == 1
            assert log_content.count(CHILD_ERROR_STR % child) == 1
            assert log_content.count(CHILD_CRITICAL_STR % child) == 1
            assert log_content.count(CHILD_DEBUG_STR % child) == 1
            assert log_content.count(CHILD_WARNING_STR % child) == 1
        assert log_content.count(PARENT_INFO_STR_1) == 1
        assert log_content.count(PARENT_ERROR_STR) == 1
        assert log_content.count(PARENT_CRITICAL_STR) == 1
        assert log_content.count(PARENT_DEBUG_STR) == 1
        assert log_content.count(PARENT_WARNING_STR) == 1
예제 #3
0
    def test_child_process_with_exception(self, tmpdir):
        log_file = self.get_logfile_path(str(tmpdir))
        openwpm_logger = mp_logger.MPLogger(log_file)

        child_process_1 = Process(target=child_proc_with_exception, args=(0, ))
        child_process_1.daemon = True
        child_process_1.start()
        child_process_2 = Process(target=child_proc_with_exception, args=(1, ))
        child_process_2.daemon = True
        child_process_2.start()

        # Close the logging server
        time.sleep(2)  # give some time for logs to be sent
        child_process_1.join()
        child_process_2.join()
        print("Child processes joined...")
        openwpm_logger.close()

        log_content = self.get_logfile_contents(log_file)
        for child in range(2):
            assert log_content.count(CHILD_INFO_STR_1 % child) == 1
            assert log_content.count(CHILD_INFO_STR_2 % child) == 1
            assert log_content.count(CHILD_EXCEPTION_STR % child) == 1