Skip to content

Commit

Permalink
Make python-regress based tests runnable with run_test.py
Browse files Browse the repository at this point in the history
For some tests such as upgrade tests and arbitrary config tests we set
up the citus cluster using Python. This setup is slightly different from
the perl based setup script (`multi_regress.pl`). Most importantly it
uses replication factor 1 by default.

This changes our run_test.py script to be able to run a schedule using
python instead of `multi_regress.pl`, for the tests that require it.

For now arbitrary config tests are still not runnable with
`run_test.py`, but this brings us one step closer to being able to do
that.

Fixes #6804
  • Loading branch information
JelteF committed Mar 31, 2023
1 parent 343d1c5 commit a0625b3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
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
58 changes: 56 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,37 @@ 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())
makefile_global_path = pgxs_path.parent.parent / "Makefile.global"
with makefile_global_path.open() as f:
contents = f.read()
srcdir_line = re.search("^abs_top_srcdir = (.*)", contents, re.MULTILINE)
if srcdir_line is None:
raise Exception("Could not find postgres source directory")
srcdir = srcdir_line.group(1)

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": srcdir,
"--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 +241,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 +282,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 +308,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

0 comments on commit a0625b3

Please sign in to comment.