From f437434ead9c0489f07361a5c787eb315edcdde4 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 10 Mar 2017 09:41:46 -0700 Subject: [PATCH] orchestra.run: Notice when short-lived procs exit If a command exits immediately, there is a race between greenlet completion (which flushes the ChannelFile buffers) and the call to exit_status_ready(). Waiting for 0.1s on the greenlets removes the race condition. Signed-off-by: Zack Cerza --- teuthology/orchestra/run.py | 1 + teuthology/orchestra/test/test_run.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/teuthology/orchestra/run.py b/teuthology/orchestra/run.py index f765edede..6f829ab35 100644 --- a/teuthology/orchestra/run.py +++ b/teuthology/orchestra/run.py @@ -179,6 +179,7 @@ class RemoteProcess(object): @property def finished(self): + gevent.wait(self.greenlets, timeout=0.1) ready = self._stdout_buf.channel.exit_status_ready() if ready: self._get_exitstatus() diff --git a/teuthology/orchestra/test/test_run.py b/teuthology/orchestra/test/test_run.py index a703b72fc..8b9b7c0c5 100644 --- a/teuthology/orchestra/test/test_run.py +++ b/teuthology/orchestra/test/test_run.py @@ -148,7 +148,7 @@ class TestRun(object): args=['foo'], check_status=False, ) - assert proc.exitstatus is None + assert proc.exitstatus == -1 def test_status_lost(self): m_transport = MagicMock() @@ -185,7 +185,7 @@ class TestRun(object): args=['foo'], check_status=False, ) - assert proc.exitstatus is None + assert proc.exitstatus == -1 def test_status_bad_nowait(self): self.m_stdout_buf.channel.recv_exit_status.return_value = 42 @@ -207,7 +207,7 @@ class TestRun(object): stdin=run.PIPE, wait=False ) - assert proc.poll() is None + assert proc.poll() == 0 code = proc.wait() assert code == 0 assert proc.exitstatus == 0 @@ -222,7 +222,7 @@ class TestRun(object): stdout=run.PIPE, wait=False ) - assert proc.poll() is None + assert proc.poll() == 0 assert proc.stdout.readline() == lines[0] assert proc.stdout.readline() == lines[1] assert proc.stdout.readline() == lines[2] @@ -240,7 +240,7 @@ class TestRun(object): stderr=run.PIPE, wait=False ) - assert proc.poll() is None + assert proc.poll() == 0 assert proc.stderr.readline() == lines[0] assert proc.stderr.readline() == lines[1] assert proc.stderr.readline() == lines[2] -- 2.47.3