Skip to content

Fix util.exit_code always returning 0 #64

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 1 commit 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
26 changes: 11 additions & 15 deletions features/steps/step_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,15 @@ def alloc_pty(ctx, f, *args, **kwargs):
client = get_client()
f(client, *args, **kwargs)
sys.exit(0)
else:
ctx.pty = fd
util.set_pty_size(
ctx.pty,
(ctx.rows, ctx.cols)
)
ctx.pid = pid
util.wait(ctx.pty, timeout=5)
time.sleep(1) # give the terminal some time to print prompt

# util.exit_code can be called only once
ctx.exit_code = util.exit_code(ctx.pid, timeout=5)
if ctx.exit_code != 0:
raise Exception("child process did not finish correctly")

ctx.pty = fd
util.set_pty_size(
ctx.pty,
(ctx.rows, ctx.cols)
)
ctx.pid = pid
ctx.exit_code = -1
util.wait(ctx.pty, timeout=5)


@given('I am using a TTY')
Expand Down Expand Up @@ -199,7 +194,8 @@ def step_impl(ctx):

@then('The PTY will be closed cleanly')
def step_impl(ctx):
if not hasattr(ctx, "exit_code"):
# if not hasattr(ctx, "exit_code"):
if ctx.exit_code < 0:
ctx.exit_code = util.exit_code(ctx.pid, timeout=5)
expect(ctx.exit_code).to(equal(0))

Expand Down
10 changes: 5 additions & 5 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ def exit_code(pid, timeout=5):

start = time.time()
while True:
_, status = os.waitpid(pid, os.WNOHANG)
if os.WIFEXITED(status):
rpid, status = os.waitpid(pid, os.WNOHANG)
if rpid != 0 and os.WIFEXITED(status):
return os.WEXITSTATUS(status)
else:
if (time.time() - start) > timeout:
return -1
if (time.time() - start) > timeout:
return -1
time.sleep(0.1)


def container_running(client, container, duration=2):
Expand Down