8000 Run isolation tests if there is `specs` folder. by ildus · Pull Request #3 · funbringer/norsu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Run isolation tests if there is specs folder. #3

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ norsu pgxs
norsu pgxs ^master -- clean install -j5

# run regression tests against 9.6.9
# installcheck (or check) will also run isolation checks in case of 'specs' folder
norsu pgxs 9.6.9 -R -- installcheck

# check using clang-analyzer for builds 9.6 and 10
Expand Down
52 changes: 50 additions & 2 deletions norsu/extension.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import os
import shlex
import shutil

from pkg_resources import resource_filename

from .config import CONFIG, TOOL_MAKE
from .exceptions import Error
from .terminal import Style
from .utils import execute, ExecOutput
from .utils import execute, ExecOutput, str_args_to_dict


class Extension:
def __init__(self, work_dir, pg_config):
self.work_dir = work_dir
self.pg_config = pg_config

def make(self, targets=None, options=None):
self.specs = None
specs_dir = os.path.join(work_dir, 'specs')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10000

We probably shouldn't hardwire specs dir name. Maybe we could add a default-able flag to the pgxs command?

if os.path.exists(specs_dir):
self.specs = [os.path.splitext(spec)[0] for spec in os.listdir(specs_dir)]

self._regress_opts = None

def get_temp_config(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a perfect candidate for being a property.

mk_var = 'EXTRA_REGRESS_OPTS'
if self._regress_opts is None:
self._regress_opts = str_args_to_dict(self.makefile_var(mk_var))

return self._regress_opts.get('--temp-config')

def make(self, targets=None, options=None, instance=None):

if not targets:
targets = CONFIG['pgxs']['default_targets']
Expand Down Expand Up @@ -50,6 +65,39 @@ def make(self, targets=None, options=None):
cwd=self.work_dir,
env=os.environ,
output=ExecOutput.Stdout)

if target in ('check', 'installcheck') and self.specs:
print(Style.green('\n$ make isolationcheck'))

tmpdir = os.path.join(self.work_dir, "tmp_check_iso")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use mkdtemp to make sure that dir name is unique? Otherwise it could result in name clash when used in parallel builds.

if os.path.exists(tmpdir):
shutil.rmtree(tmpdir)

isolation_args = [
os.path.join(instance.work_dir,
"src/test/isolation/pg_isolation_regress"),
"--temp-instance=%s" % tmpdir,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshedding: I personally prefer format to %, since this is a recommended way of string formatting in 3.0+. Could you rewrite those pieces of code, please?

"--inputdir=.",
"--outputdir=output_iso",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needless contraction -- output_isolation?

"--bindir=%s" % instance.get_bin_path(""),
]

temp_config = self.get_temp_config()
if temp_config:
isolation_args.append("--temp-config=%s" % temp_config)

for spec in self.specs:
isolation_args.append(spec)

try:
execute(isolation_args,
cwd=self.work_dir,
env=os.environ,
output=ExecOutput.Stdout)
finally:
if os.path.exists(tmpdir):
shutil.rmtree(tmpdir)

print()

def makefile_var(self, name):
Expand Down
19 changes: 7 additions & 12 deletions norsu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from .utils import (
partition,
give_terminal_to,
str_args_to_dict,
)


Expand Down Expand Up @@ -118,10 +117,9 @@ def cmd_run(main_args, psql_args):
# Grab extra extension options
if main_args.pgxs:
extension = Extension(work_dir=work_dir, pg_config=pg_config)

mk_var = 'EXTRA_REGRESS_OPTS'
regress_opts = str_args_to_dict(extension.makefile_var(mk_var))
config_files.append(regress_opts.get('--temp-config'))
temp_config = extension.get_temp_config()
if temp_config:
config_files.append(temp_config)

# Grab extra PG config files
if main_args.config:
Expand Down Expand Up @@ -184,16 +182,13 @@ def cmd_pgxs(main_args, make_args):
# should we start PostgreSQL?
if main_args.run_pg:
port = main_args.run_pg_port

mk_var = 'EXTRA_REGRESS_OPTS'
regress_opts = str_args_to_dict(extension.makefile_var(mk_var))
config_files = [regress_opts.get('--temp-config')]
temp_config = extension.get_temp_config()

# run commands under a running PostgreSQL instance
with run_temp(instance, config_files=config_files, port=port) as node:
with run_temp(instance, config_files=[temp_config], port=port) as node:
# make pg_regress aware of non-default port
make_opts.append('{}+=--port={}'.format(mk_var, node.port))
extension.make(targets=make_targets, options=make_opts)
make_opts.append('EXTRA_REGRESS_OPTS+=--port=%s' % node.port)
extension.make(targets=make_targets, options=make_opts, instance=instance)
else:
extension.make(targets=make_targets, options=make_opts)

Expand Down
0