def execute(tests_dir, conn, num_workers): runner = TestRunner() unittest.main(module=None, argv=['unittest', 'discover', '-s', tests_dir], testRunner=runner, exit=False) tb.setup_test_cases(runner.cases, conn, num_workers)
def execute(tests_dir, conn, num_workers, include): runner = TestRunner() include = [x for pat in include for x in ['-k', pat]] unittest.main(module=None, argv=['unittest', 'discover', '-s', tests_dir, *include], testRunner=runner, exit=False) tb.setup_test_cases(runner.cases, conn, num_workers)
def run(self, test): session_start = time.monotonic() cases = tb.get_test_cases([test]) setup = tb.get_test_cases_setup(cases) bootstrap_time_taken = 0 tests_time_taken = 0 result = None cluster = None conn = None try: if setup: if self.verbosity >= 1: self._echo( 'Populating test databases... ', fg='white', nl=False, ) if self.verbosity > 1: self._echo( '\n -> Bootstrapping EdgeDB instance...', fg='white', nl=False, ) cluster = tb._init_cluster(cleanup_atexit=False) if self.verbosity > 1: self._echo(' OK') conn = cluster.get_connect_args() tb.setup_test_cases( cases, conn, self.num_workers, verbose=self.verbosity > 1, ) os.environ.update({ 'EDGEDB_TEST_CASES_SET_UP': "1" }) bootstrap_time_taken = time.monotonic() - session_start if self.verbosity >= 1: self._echo(' OK') start = time.monotonic() all_tests = list(itertools.chain.from_iterable( tests for tests in cases.values())) if self.num_workers > 1: suite = ParallelTestSuite( self._sort_tests(cases), conn, self.num_workers) else: suite = SequentialTestSuite( self._sort_tests(cases), conn ) result = ParallelTextTestResult( stream=self.stream, verbosity=self.verbosity, warnings=self.warnings, failfast=self.failfast, output_format=self.output_format, tests=all_tests, suite=suite) unittest.signals.registerResult(result) self._echo() suite.run(result) tests_time_taken = time.monotonic() - start except KeyboardInterrupt: raise finally: if self.verbosity == 1: self._echo() if setup: self._echo() self._echo('Shutting down test cluster... ', nl=False) tb._shutdown_cluster(cluster, destroy=True) self._echo('OK.') if result is not None: self._render_result( result, bootstrap_time_taken, tests_time_taken) return result
version: str) -> None: runner = TestRunner() unittest.main( module=None, argv=["unittest", "discover", "-s", tests_dir], testRunner=runner, exit=False, ) setup_scripts = tb.get_test_cases_setup(runner.cases) dump_cases = { db_name: case for case, db_name, _ss in setup_scripts if getattr(case, "STABLE_DUMP", False) } tb.setup_test_cases(list(dump_cases.values()), conn, num_workers) dumps_dir = pathlib.Path(tests_dir) / "dumps" db_friendly_version = version.split("+", 1)[0] db_friendly_version = db_friendly_version.replace("-alpha.", "a") db_friendly_version = db_friendly_version.replace("-beta.", "b") db_friendly_version = db_friendly_version.replace("-rc.", "rc") db_friendly_version = db_friendly_version.replace("-", "_") db_friendly_version = db_friendly_version.replace(".", "_") for db_name in dump_cases: with tempfile.NamedTemporaryFile() as f: tb.CLITestCaseMixin.run_cli_on_connection(conn, "-d", db_name, "dump", f.name) db_dumps_dir = dumps_dir / db_name db_dumps_dir.mkdir(exist_ok=True) dump_p = (db_dumps_dir / db_friendly_version).with_suffix(".dump")
def run(self, test, selected_shard, total_shards, running_times_log_file): session_start = time.monotonic() cases = tb.get_test_cases([test]) stats = {} if running_times_log_file: running_times_log_file.seek(0) stats = { k: (float(v), int(c)) for k, v, c in csv.reader(running_times_log_file) } cases = tb.get_cases_by_shard( cases, selected_shard, total_shards, self.verbosity, stats, ) setup = tb.get_test_cases_setup(cases) bootstrap_time_taken = 0 tests_time_taken = 0 result = None cluster = None conn = None setup_stats = [] try: if setup: if self.verbosity >= 1: self._echo( 'Populating test databases... ', fg='white', nl=False, ) if self.verbosity > 1: self._echo( '\n -> Bootstrapping EdgeDB instance...', fg='white', nl=False, ) cluster = tb._init_cluster(postgres_dsn=self.postgres_dsn, cleanup_atexit=False) if self.verbosity > 1: self._echo(' OK') conn = cluster.get_connect_args() setup_stats = tb.setup_test_cases( cases, conn, self.num_workers, verbose=self.verbosity > 1, ) os.environ.update({'EDGEDB_TEST_CASES_SET_UP': "1"}) bootstrap_time_taken = time.monotonic() - session_start if self.verbosity >= 1: self._echo('OK') start = time.monotonic() all_tests = list( itertools.chain.from_iterable(tests for tests in cases.values())) if self.num_workers > 1: suite = ParallelTestSuite( self._sort_tests(cases), conn, self.num_workers, self.postgres_dsn, ) else: suite = SequentialTestSuite( self._sort_tests(cases), conn, self.postgres_dsn, ) result = ParallelTextTestResult(stream=self.stream, verbosity=self.verbosity, warnings=self.warnings, failfast=self.failfast, output_format=self.output_format, tests=all_tests, suite=suite) unittest.signals.registerResult(result) self._echo() suite.run(result) if running_times_log_file: for test, stat in result.test_stats + setup_stats: name = str(test) t = stat['running-time'] at, c = stats.get(name, (0, 0)) stats[name] = (at + (t - at) / (c + 1), c + 1) running_times_log_file.seek(0) running_times_log_file.truncate() writer = csv.writer(running_times_log_file) for k, v in stats.items(): writer.writerow((k, ) + v) tests_time_taken = time.monotonic() - start except KeyboardInterrupt: raise finally: if self.verbosity == 1: self._echo() if setup: self._echo() self._echo('Shutting down test cluster... ', nl=False) tb._shutdown_cluster(cluster, destroy=True) self._echo('OK.') if result is not None: self._render_result(result, bootstrap_time_taken, tests_time_taken) return result