Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make python-regress based tests runnable with run_test.py #6814

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/test/regress/citus_tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ def run(command, *args, check=True, shell=True, silent=False, **kwargs):
return subprocess.run(command, *args, check=check, shell=shell, **kwargs)


def capture(command, *args, **kwargs):
"""runs the given command and returns its output as a string"""
return run(command, *args, stdout=subprocess.PIPE, text=True, **kwargs).stdout


def sudo(command, *args, shell=True, **kwargs):
"""
A version of run that prefixes the command with sudo when the process is
Expand Down
51 changes: 49 additions & 2 deletions src/test/regress/citus_tests/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import common

import config
from config import ARBITRARY_SCHEDULE_NAMES, MASTER_VERSION, CitusDefaultClusterConfig


# Returns true if given test_schedule_line is of the form:
Expand Down Expand Up @@ -46,6 +46,30 @@ def run_python_test(test_file_name, repeat):
)


def run_schedule_with_python(schedule):
bindir = common.capture("pg_config --bindir").rstrip()
pgxs_path = pathlib.Path(common.capture("pg_config --pgxs").rstrip())

os.chdir(regress_dir)
os.environ["PATH"] = str(regress_dir / "bin") + os.pathsep + os.environ["PATH"]
os.environ["PG_REGRESS_DIFF_OPTS"] = "-dU10 -w"
os.environ["CITUS_OLD_VERSION"] = f"v{MASTER_VERSION}.0"

args = {
"--pgxsdir": str(pgxs_path.parent.parent.parent),
"--bindir": bindir,
}

config = CitusDefaultClusterConfig(args)
common.initialize_temp_dir(config.temp_dir)
common.initialize_citus_cluster(
config.bindir, config.datadir, config.settings, config
)
common.run_pg_regress(
config.bindir, config.pg_srcdir, config.coordinator_port(), schedule
)


if __name__ == "__main__":
args = argparse.ArgumentParser()
args.add_argument(
Expand Down Expand Up @@ -210,7 +234,19 @@ def default_base_schedule(test_schedule):
if "operations" in test_schedule:
return "minimal_schedule"

if test_schedule in config.ARBITRARY_SCHEDULE_NAMES:
if "after_citus_upgrade" in test_schedule:
print(
f"WARNING: After citus upgrade schedule ({test_schedule}) is not supported."
)
sys.exit(0)

if "citus_upgrade" in test_schedule:
return None

if "pg_upgrade" in test_schedule:
return "minimal_schedule"

if test_schedule in ARBITRARY_SCHEDULE_NAMES:
print(
f"WARNING: Arbitrary config schedule ({test_schedule}) is not supported."
)
Expand Down Expand Up @@ -239,6 +275,9 @@ def worker_count_for(test_name):
else:
dependencies = TestDeps(default_base_schedule(test_schedule))

if "before_" in test_schedule:
dependencies.repeatable = False

# copy base schedule to a temp file and append test_schedule_line
# to be able to run tests in parallel (if test_schedule_line is a parallel group.)
tmp_schedule_path = os.path.join(
Expand All @@ -262,6 +301,14 @@ def worker_count_for(test_name):
for _ in range(repetition_cnt):
myfile.write(test_schedule_line)

if "upgrade" in test_schedule_line:
try:
run_schedule_with_python(pathlib.Path(tmp_schedule_path).stem)
finally:
# remove temp schedule file
os.remove(tmp_schedule_path)
sys.exit(0)

# find suitable make recipe
if dependencies.schedule == "base_isolation_schedule":
make_recipe = "check-isolation-custom-schedule"
Expand Down