IMPALA-7407: Fix test_cancellation failure on KeyboardInterrupt test_cancellation runs a shell process, executes a query, sleeps, sends a sigint to the process, and then checks that the query is cancelled. If the sigint is sent prior to the shell installing its signal handler, the test can fail with a KeyboardInterrupt.
This patch removes the reliance on the sleep being long enough by actually reading the output of the shell and only cancelling the query once the shell shows that it has started running. Testing: - Ran test_cancellation in a loop. Change-Id: I65302ffb838d5185f77853bc2e53296f3a701d93 Reviewed-on: http://gerrit.cloudera.org:8080/11255 Tested-by: Impala Public Jenkins <[email protected]> Reviewed-by: Thomas Marshall <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/impala/repo Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/dccc2de8 Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/dccc2de8 Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/dccc2de8 Branch: refs/heads/master Commit: dccc2de86a01e1a109f215c1a08d118471f57ca4 Parents: f8f200e Author: Thomas Tauber-Marshall <[email protected]> Authored: Tue Aug 14 20:43:52 2018 +0000 Committer: Thomas Marshall <[email protected]> Committed: Mon Aug 20 19:56:11 2018 +0000 ---------------------------------------------------------------------- tests/shell/test_shell_commandline.py | 2 +- tests/shell/util.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/impala/blob/dccc2de8/tests/shell/test_shell_commandline.py ---------------------------------------------------------------------- diff --git a/tests/shell/test_shell_commandline.py b/tests/shell/test_shell_commandline.py index b0f2f03..0f73620 100644 --- a/tests/shell/test_shell_commandline.py +++ b/tests/shell/test_shell_commandline.py @@ -340,7 +340,7 @@ class TestImpalaShell(ImpalaTestSuite): query = "set num_nodes=1; set mt_dop=1; set batch_size=1; \ select sleep(10) from functional_parquet.alltypesagg" p = ImpalaShell('-q "{0}"'.format(query)) - sleep(6) + p.wait_for_query_start() os.kill(p.pid(), signal.SIGINT) result = p.get_result() http://git-wip-us.apache.org/repos/asf/impala/blob/dccc2de8/tests/shell/util.py ---------------------------------------------------------------------- diff --git a/tests/shell/util.py b/tests/shell/util.py index 0c899ab..6c1df0e 100755 --- a/tests/shell/util.py +++ b/tests/shell/util.py @@ -136,6 +136,22 @@ class ImpalaShell(object): # Allow fluent-style chaining of commands return self + def wait_for_query_start(self): + """If this shell was started with the '-q' option, this mathod will block until the + query has started running""" + # readline() will block until a line is actually printed, so this loop should always + # read something like: + # Starting Impala Shell without Kerberos authentication + # Connected to localhost:21000 + # Server version: impalad version... + # Query: select sleep(10) + # Query submitted at:... + # Query progress can be monitored at:... + # We stop at 10 iterations to prevent an infinite loop if somehting goes wrong. + iters = 0 + while "Query progress" not in self.shell_process.stderr.readline() and iters < 10: + iters += 1 + def get_result(self, stdin_input=None): """Returns an ImpalaShellResult produced by the shell process on exit. After this method returns, send_cmd() no longer has any effect."""
