From 21c13fb393e306df6c88dc51cba20e1e783a8bea Mon Sep 17 00:00:00 2001 From: Jacob Champion Date: Sun, 7 Jan 2018 11:40:34 -0800 Subject: [PATCH] isolation2: add an exit-code-only execution mode We don't want to diff the output from `segwalrep.py recoverfull`, but we do want to know if the command has succeeded or not. Add a new execution mode, invoked via !\retcode EXECUTABLE [OPTIONS ...] which will bracket the program's stdout/stderr with begin/end_ignore, and also print out an exit code (which is not ignored). --- src/test/isolation2/sql_isolation_testcase.py | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/test/isolation2/sql_isolation_testcase.py b/src/test/isolation2/sql_isolation_testcase.py index 4ed1772ba2..dd57f32b4c 100644 --- a/src/test/isolation2/sql_isolation_testcase.py +++ b/src/test/isolation2/sql_isolation_testcase.py @@ -269,9 +269,29 @@ class SQLIsolationExecutor(object): sql = sql_parts[1] if not flag: if sql.startswith('!'): - cmd_output = subprocess.Popen(sql[1:].strip(), stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True) + sql = sql[1:] + + # Check for execution mode. E.g. + # !\retcode path/to/executable --option1 --option2 ... + # + # At the moment, we only recognize the \retcode mode, which + # ignores all program output in the diff (it's still printed) + # and adds the return code. + mode = None + if sql.startswith('\\'): + mode, sql = sql.split(None, 1) + if mode != '\\retcode': + raise Exception('Invalid execution mode: {}'.format(mode)) + + cmd_output = subprocess.Popen(sql.strip(), stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True) + stdout, _ = cmd_output.communicate() print >> output_file - print >> output_file, cmd_output.stdout.read() + if mode == '\\retcode': + print >> output_file, '-- start_ignore' + print >> output_file, stdout + if mode == '\\retcode': + print >> output_file, '-- end_ignore' + print >> output_file, '(exited with code {})'.format(cmd_output.returncode) else: self.get_process(output_file, process_name, dbname=dbname).query(sql.strip()) elif flag == "&": -- GitLab