Skip to content

Commit

Permalink
Fix some progress bar tests failing silently
Browse files Browse the repository at this point in the history
Fixes a bug where some progress bar subtests (testing functionality
in a simulated interactive session) would fail silently and
erroneously report success because child process exit code was
not checked.

Also makes some small improvements to test assertion semantics.
  • Loading branch information
natanlao committed Dec 3, 2019
1 parent 025852c commit d53829e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/integration/dss/test_dss_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,40 @@ def test_upload_progress_bar_interactive(self):
hca.cli.main(args=put_args)
os._exit(0)
output = self._get_child_output(child_pid, fd)
self.assertTrue('Uploading to aws' in output, output)
self.assertIn('Uploading to aws: 100%', output)

with self.subTest("Don't show progress bar if interactive and not logging INFO"):
child_pid, fd = pty.fork()
if child_pid == 0:
hca.cli.main(args=['--log-level', 'WARNING'] + put_args)
os._exit(0)
output = self._get_child_output(child_pid, fd)
self.assertFalse('Uploading to aws' in output, output)
self.assertNotIn('Uploading to aws', output)

with self.subTest("Don't show progress bar if interactive and --no-progress"):
child_pid, fd = pty.fork()
if child_pid == 0:
hca.cli.main(args=put_args + ['--no-progress'])
os._exit(0)
output = self._get_child_output(child_pid, fd)
self.assertFalse('Uploading to aws' in output, output)
self.assertNotIn('Uploading to aws', output)

@staticmethod
def _get_child_output(child_pid, fd):
def _get_child_output(self, child_pid, fd):
output = ''
while not os.waitpid(child_pid, os.WNOHANG)[0]:
while True:
stopped, status = os.waitpid(child_pid, os.WNOHANG)
if stopped:
break
try:
output += os.read(fd, 128).decode()
buf = os.read(fd, 128).decode()
print(buf, end='')
output += buf
except OSError:
break
os.close(fd)
exit_code = os.WEXITSTATUS(status)
if exit_code != 0:
self.fail("Child process exited with %d" % exit_code)
return output

@staticmethod
Expand Down

0 comments on commit d53829e

Please sign in to comment.