From 649225166a7a3b488d43de48dd04471b16a7802c Mon Sep 17 00:00:00 2001 From: Tim Head Date: Sat, 23 Mar 2019 22:07:36 +0100 Subject: [PATCH] Update test of editable flag For some reason the notebook server doesn't exit when we send the SIGTERM signal to the container and as a result waiting for the container to shutdown leads to an exit code of 137 (the notebook server gets kill by SIGKILL). --- tests/unit/test_editable.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_editable.py b/tests/unit/test_editable.py index 87d66ee6..6a015153 100644 --- a/tests/unit/test_editable.py +++ b/tests/unit/test_editable.py @@ -3,10 +3,8 @@ import re import tempfile import time -from repo2docker.app import Repo2Docker from repo2docker.__main__ import make_r2d -from conftest import make_test_func DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'dockerfile', 'editable') @@ -39,19 +37,26 @@ def test_editable_by_host(): app.initialize() app.build() container = app.start_container() + # give the container a chance to start - time.sleep(1) + while container.status != 'running': + time.sleep(1) + try: with tempfile.NamedTemporaryFile(dir=DIR, prefix='testfile', suffix='.txt'): status, output = container.exec_run(['sh', '-c', 'ls testfile????????.txt']) assert status == 0 assert re.match(br'^testfile\w{8}\.txt\n$', output) is not None - # File should be removed in the container as well + # After exiting the with block the file should stop existing + # in the container as well as locally status, output = container.exec_run(['sh', '-c', 'ls testfile????????.txt']) - assert status != 1 + assert status == 2 assert re.match(br'^testfile\w{8}\.txt\n$', output) is None finally: - # stop the container - container.stop() - app.wait_for_container(container) + # stop the container, we don't care how it stops or + # what the exit code is. + container.stop(timeout=1) + container.reload() + assert container.status == 'exited', container.status + container.remove()