Ejemplo n.º 1
0
def main():
    load_plugins()
    args = parse_args()

    if args.output:
        sys.stdout = io.open(args.output, 'w')

    directives = []
    for filename in args.input_filenames:
        directives.extend(generate_directives_from_file(filename, args))

    logger = get_logger(args)
    logger.start()
    failed = True
    for pass_ in range(args.passes):
        if pass_:
            sleep(args.delay_between_passes)
        logger.start_pass()
        threads, stop_event = get_threads_and_stop_event(
            directives,
            args.threads,
        )

        # Start the tests
        for thread in threads:
            thread.start()

        # Wait for tests to finish
        try:
            # Using threading.active_count() > 1 here causes a problem where a
            # keyboard interrupt sometimes results in the program hanging...
            # not sure why.
            while any(alive_threads(threads)):
                pass
        except KeyboardInterrupt:
            # Write to console even if output is going to file
            sys.__stdout__.write(
                '\nWaiting for {0} thread{1} to stop...'.format(
                    len(threads),
                    '' if len(threads) == 1 else 's',
                ))
            sys.__stdout__.flush()
            stop_event.set()
            while any(alive_threads(threads)):
                for thread in threads:
                    thread.join(0.1)
            sys.__stdout__.write('\nSmoketest cancelled by user.\n')
            sys.__stdout__.flush()
            break

        logger.end_pass()

        directives = [d for d in directives if getattr(d, 'failed', True)]
        if not directives:
            failed = False
            break

    logger.end()

    sys.exit(1) if failed else sys.exit(0)
Ejemplo n.º 2
0
 def __init__(self, elem, options):
     self.options = options
     self.elem = elem
     self.timeout = elem.get('timeout', get_default_request_timeout())
     self.urls = get_urls_from_element(elem, options)
     self.tests = get_tests_from_element(elem, options)
     self.logger = get_logger(self.options)
     self.platforms = get_platforms_from_element(elem)
     self.follow_redirects = elem.get('follow_redirects', False)
Ejemplo n.º 3
0
    def test_default_logger_decorator(self):
        # Create a custom logger
        from smoketest.loggers import (
            Constants,
            Logger,
            default_logger,
            get_logger,
            select_with_key,
        )
        Constants.clear()

        @default_logger
        @select_with_key('mylogger')
        class MyLogger(Logger):
            pass

        # Check that get_logger function gives us the new default
        options = Mock()
        logger = get_logger(options)
        self.assertIsInstance(logger, MyLogger)
Ejemplo n.º 4
0
    def test_select_with_key_decorator(self):
        # Create a custom logger
        from smoketest.loggers import (
            Constants,
            Logger,
            get_logger,
            select_with_key,
        )
        Constants.clear()
        key = 'mylogger'

        @select_with_key(key)
        class MyLogger(Logger):
            pass

        # Try getting it with get_logger
        options = Mock()
        options.format = key
        logger = get_logger(options)
        self.assertIsInstance(logger, MyLogger)
Ejemplo n.º 5
0
def main():
    load_plugins()
    args = parse_args()

    if args.output:
        sys.stdout = io.open(args.output, 'w')

    directives = []
    for filename in args.input_filenames:
        try:
            directives.extend(generate_directives_from_file(filename, args))
        except InputFileError as e:
            print('Smoketest had a problem with the input file "{0}":'.format(
                e.filename
            ))
            print(e)
            sys.exit(1)

    logger = get_logger(args)
    logger.start()
    failed = True
    for pass_ in range(args.passes):
        if pass_:
            sleep(args.delay_between_passes)
        logger.start_pass()
        threads, stop_event = get_threads_and_stop_event(
            directives,
            args.threads,
        )

        # Start the tests
        for thread in threads:
            thread.start()

        # Wait for tests to finish
        try:
            # Using threading.active_count() > 1 here causes a problem where a
            # keyboard interrupt sometimes results in the program hanging...
            # not sure why.
            while any(alive_threads(threads)):
                pass
        except KeyboardInterrupt:
            # Write to console even if output is going to file
            sys.__stdout__.write('\nWaiting for {0} thread{1} to stop...'.format(
                len(threads),
                '' if len(threads) == 1 else 's',
            ))
            sys.__stdout__.flush()
            stop_event.set()
            while any(alive_threads(threads)):
                for thread in threads:
                    thread.join(0.1)
            sys.__stdout__.write('\nSmoketest cancelled by user.\n')
            sys.__stdout__.flush()
            break

        logger.end_pass()

        directives = [d for d in directives if getattr(d, 'failed', True)]
        if not directives:
            failed = False
            break

    logger.end()

    sys.exit(1) if failed else sys.exit(0)