From d3feee37ea928f78e58dc90883f6ab8793984406 Mon Sep 17 00:00:00 2001 From: Jelte Fennema Date: Tue, 1 Jun 2021 11:22:11 +0200 Subject: [PATCH] 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 --- src/test/regress/bin/create_test.py | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 src/test/regress/bin/create_test.py diff --git a/src/test/regress/bin/create_test.py b/src/test/regress/bin/create_test.py new file mode 100755 index 000000000..572d64510 --- /dev/null +++ b/src/test/regress/bin/create_test.py @@ -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")