Beispiel #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)
Beispiel #2
0
    def test_generate_directives_from_nonexistent_file(self):
        from smoketest.directives import (
            InputFileError,
            generate_directives_from_file,
        )
        self.assertRaises(
            InputFileError,
            next,
            generate_directives_from_file('fake.txt', None)
        )

        self.assertRaises(
            InputFileError,
            next,
            generate_directives_from_file('fake.yaml', None),
        )
Beispiel #3
0
    def test_generate_directives_from_invalid_json_file(self):
        from smoketest.directives import (
            InputFileError,
            generate_directives_from_file,
        )
        invalid_json_file = self._create_file('.json')
        invalid_json_file.write('x')
        invalid_json_file.close()

        self.assertRaises(
            InputFileError,
            next,
            generate_directives_from_file(invalid_json_file.name, None)
        )
Beispiel #4
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)