Add a simple python script to generate a new test (#3972)

The current default citus settings for tests are not really best
practice anymore. However, we keep them because lots of tests depend on
them.

I noticed that I created the same test harness for new tests I added all
the time. This is a simple script that generates that harness, given a
name for the test.

To run:

src/test/regress/bin/create_test.py my_awesome_test
pull/5010/head
Jelte Fennema 2021-06-01 11:22:11 +02:00 committed by GitHub
parent c72d2b479b
commit d3feee37ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
#!/usr/bin/env python3
import sys
import random
import os
if len(sys.argv) != 2:
print(
"ERROR: Expected the name of the new test as an argument, such as:\n"
"src/test/regress/bin/create_test.py my_awesome_test"
)
sys.exit(1)
test_name = sys.argv[1]
regress_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
filename = os.path.join(regress_dir, "sql", f"{test_name}.sql")
if os.path.isfile(filename):
print(f"ERROR: test file '{filename}' already exists")
sys.exit(1)
shard_id = random.randint(1, 999999) * 100
contents = f"""CREATE SCHEMA {test_name};
SET search_path TO {test_name};
SET citus.shard_count TO 4;
SET citus.shard_replication_factor TO 1;
SET citus.next_shard_id TO {shard_id};
-- add tests here
SET client_min_messages TO WARNING;
DROP SCHEMA {test_name} CASCADE;
"""
with open(filename, "w") as f:
f.write(contents)
print(f"Created {filename}")
print(f"Don't forget to add '{test_name}' in multi_schedule somewhere")