Exemplo n.º 1
0
 def test_exception_no_fork(self):
     with OutputCapture(level=logging.INFO) as captured:
         with self.assertRaises(RuntimeError):
             with TaskPool(workers=1, force_fork=False) as pool:
                 pool.do(exception, 'Testing exception')
                 pool.wait()
     self.assertEqual(captured.webkitcorepy.log.getvalue(), '')
Exemplo n.º 2
0
    def test_single_no_fork(self):
        with OutputCapture(level=logging.WARNING) as captured:
            with TaskPool(workers=1, force_fork=False) as pool:
                pool.do(action, 'a')
                pool.do(log, logging.WARNING, '1')
                pool.wait()

        self.assertEqual(captured.stdout.getvalue(), 'action(a)\n')
        self.assertEqual(captured.webkitcorepy.log.getvalue(), '1\n')
Exemplo n.º 3
0
 def test_teardown_arguments(self):
     with OutputCapture() as captured:
         with TaskPool(workers=4, teardown=teardown, teardownargs=['Teardown argument']) as pool:
             for character in self.alphabet:
                 pool.do(action, character)
             pool.wait()
     self.assertEqual(
         sorted(captured.webkitcorepy.log.getvalue().splitlines()),
         ['worker/{} Teardown argument'.format(x) for x in range(4)],
     )
Exemplo n.º 4
0
 def test_setup(self):
     with OutputCapture() as captured:
         with TaskPool(workers=4, setup=setup) as pool:
             for character in self.alphabet:
                 pool.do(action, character)
             pool.wait()
     self.assertEqual(
         sorted(captured.webkitcorepy.log.getvalue().splitlines()),
         ['worker/{} Setting up'.format(x) for x in range(4)],
     )
Exemplo n.º 5
0
 def test_exception(self):
     with OutputCapture(level=logging.INFO) as captured:
         with self.assertRaises(RuntimeError):
             with TaskPool(workers=1, force_fork=True) as pool:
                 pool.do(exception, 'Testing exception')
                 pool.wait()
     self.assertEqual(
         captured.webkitcorepy.log.getvalue().splitlines(),
         ['worker/0 starting', 'worker/0 stopping'],
     )
Exemplo n.º 6
0
    def test_callback(self):
        sequence = []

        with OutputCapture():
            with TaskPool(workers=4) as pool:
                for character in self.alphabet:
                    pool.do(action, character, callback=lambda value: sequence.append(value))
                pool.wait()
        self.assertEqual(
            self.alphabet,
            ''.join(sorted(sequence)),
        )
Exemplo n.º 7
0
    def test_multiple(self):
        with OutputCapture(level=logging.INFO) as captured:
            with TaskPool(workers=4) as pool:
                for character in self.alphabet:
                    pool.do(action, character)
                pool.wait()

        lines = captured.stdout.getvalue().splitlines()
        self.assertEquals(sorted(lines), ['action({})'.format(character) for character in self.alphabet])
        self.assertEqual(
            sorted(captured.webkitcorepy.log.getvalue().splitlines()),
            sorted(['worker/{} starting'.format(number) for number in range(4)] + ['worker/{} stopping'.format(number) for number in range(4)]),
        )
Exemplo n.º 8
0
    def run(self, tests, num_workers):
        if not tests:
            return

        self.printer.write_update('Sharding tests ...')
        shards = Runner._shard_tests(tests)

        original_level = server_process_logger.level
        server_process_logger.setLevel(logging.CRITICAL)

        try:
            if Runner.instance:
                raise RuntimeError('Cannot nest API test runners')
            Runner.instance = self
            self._num_workers = min(num_workers, len(shards))

            devices = None
            if getattr(self.port, 'DEVICE_MANAGER', None):
                devices = dict(
                    available_devices=self.port.DEVICE_MANAGER.
                    AVAILABLE_DEVICES,
                    initialized_devices=self.port.DEVICE_MANAGER.
                    INITIALIZED_DEVICES,
                )

            with TaskPool(
                    workers=self._num_workers,
                    setup=setup_shard,
                    setupkwargs=dict(port=self.port, devices=devices),
                    teardown=teardown_shard,
            ) as pool:
                for name, tests in iteritems(shards):
                    pool.do(run_shard, name, *tests)
                pool.wait()

        finally:
            server_process_logger.setLevel(original_level)
            Runner.instance = None
Exemplo n.º 9
0
 def test_invalid_shutdown(self):
     with OutputCapture():
         with self.assertRaises(TaskPool.Exception):
             with TaskPool(workers=1, teardown=teardown, grace_period=1, force_fork=True) as pool:
                 pool.do(wait, 2)
Exemplo n.º 10
0
    def run_tests(self,
                  expectations,
                  test_inputs,
                  num_workers,
                  retrying,
                  device_type=None):
        self._expectations = expectations
        self._test_inputs = list(test_inputs)

        self._retrying = retrying

        # FIXME: rename all variables to test_run_results or some such ...
        run_results = TestRunResults(self._expectations, len(test_inputs))
        self._current_run_results = run_results
        self.printer.num_tests = len(test_inputs)
        self.printer.num_started = 0

        if not retrying:
            self.printer.print_expected(
                run_results,
                self._expectations.model().get_tests_with_result_type)

        self.printer.write_update('Sharding tests ...')
        all_shards = self._sharder.shard_tests(
            test_inputs, int(self._options.child_processes),
            self._options.fully_parallel)

        num_workers = min(num_workers, len(all_shards))
        self.printer.print_workers_and_shards(num_workers, len(all_shards))

        if self._options.dry_run:
            return run_results

        self.printer.write_update('Starting {} ...'.format(
            pluralize(num_workers, "worker")))

        devices = None
        if getattr(self._port, 'DEVICE_MANAGER', None):
            devices = dict(
                available_devices=self._port.DEVICE_MANAGER.AVAILABLE_DEVICES,
                initialized_devices=self._port.DEVICE_MANAGER.
                INITIALIZED_DEVICES,
            )

        try:
            LayoutTestRunner.instance = self
            with TaskPool(
                    workers=num_workers,
                    setup=setup_shard,
                    setupkwargs=dict(
                        port=self._port,
                        devices=devices,
                        results_directory=self._results_directory,
                        retrying=self._retrying,
                    ),
                    teardown=teardown_shard,
            ) as pool:
                for shard in all_shards:
                    pool.do(
                        run_shard,
                        shard,
                        callback=lambda value: self.
                        _annotate_results_with_additional_failures(value),
                    )
                pool.wait()

        except TestRunInterruptedException as e:
            _log.warning(e.reason)
            run_results.interrupted = True
        except KeyboardInterrupt:
            self.printer.flush()
            self.printer.writeln('Interrupted, exiting ...')
            run_results.keyboard_interrupted = True
        except Exception as e:
            _log.debug('{}("{}") raised, exiting'.format(
                e.__class__.__name__, str(e)))
            raise
        finally:
            LayoutTestRunner.instance = None

        return run_results