Skip to content

Commit

Permalink
Increase timeout in test_example_from_env_yaml (#708)
Browse files Browse the repository at this point in the history
* expose timeout kwarg

* increase timeout in test_example_from_env_yaml

* make it more explicit
  • Loading branch information
jaimergp authored Aug 8, 2023
1 parent 1e622a3 commit fa82997
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/from_env_yaml/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name: testenv
channels:
- defaults
dependencies:
- python
- conda
- python=3.9
- conda=23.3
34 changes: 18 additions & 16 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


def _execute(
cmd: Iterable[str], installer_input=None, check=True, **env_vars
cmd: Iterable[str], installer_input=None, check=True, timeout=420, **env_vars
) -> subprocess.CompletedProcess:
t0 = time.time()
if env_vars:
Expand All @@ -54,7 +54,7 @@ def _execute(
)
stdout, stderr = None, None
try:
stdout, stderr = p.communicate(input=installer_input, timeout=420)
stdout, stderr = p.communicate(input=installer_input, timeout=timeout)
retcode = p.poll()
if check and retcode:
raise subprocess.CalledProcessError(retcode, cmd, output=stdout, stderr=stderr)
Expand All @@ -71,7 +71,7 @@ def _execute(
print("Took", timedelta(seconds=time.time() - t0))


def _run_installer_exe(installer, install_dir, installer_input=None):
def _run_installer_exe(installer, install_dir, installer_input=None, timeout=420):
"""
NSIS manual:
> /D sets the default installation directory ($INSTDIR), overriding InstallDir
Expand All @@ -94,7 +94,7 @@ def _run_installer_exe(installer, install_dir, installer_input=None):
"after completion."
)
cmd = ["cmd.exe", "/c", "start", "/wait", installer, "/S", *f"/D={install_dir}".split()]
_execute(cmd)
_execute(cmd, installer_input=installer_input, timeout=timeout)

# Windows installers won't raise exit codes so we need to check the log file
error_lines = []
Expand All @@ -118,7 +118,7 @@ def _run_installer_exe(installer, install_dir, installer_input=None):
raise AssertionError("\n".join(error_lines))


def _run_uninstaller_exe(install_dir):
def _run_uninstaller_exe(install_dir, timeout=420):
# Now test the uninstallers
if " " in str(install_dir):
# TODO: We can't seem to run the uninstaller when there are spaces in the PATH
Expand All @@ -143,7 +143,7 @@ def _run_uninstaller_exe(install_dir):
# us problems with the tempdir cleanup later
f"/S _?={install_dir}",
]
_execute(cmd)
_execute(cmd, timeout=timeout)
remaining_files = list(install_dir.iterdir())
if len(remaining_files) > 2:
# The debug installer writes to install.log too, which will only
Expand All @@ -155,15 +155,15 @@ def _run_uninstaller_exe(install_dir):
raise AssertionError(f"Uninstaller left too many files: {remaining_files}")


def _run_installer_sh(installer, install_dir, installer_input=None):
def _run_installer_sh(installer, install_dir, installer_input=None, timeout=420):
if installer_input:
cmd = ["/bin/sh", installer]
else:
cmd = ["/bin/sh", installer, "-b", "-p", install_dir]
return _execute(cmd, installer_input=installer_input)
return _execute(cmd, installer_input=installer_input, timeout=timeout)


def _run_installer_pkg(installer, install_dir, example_path=None):
def _run_installer_pkg(installer, install_dir, example_path=None, timeout=420):
if os.environ.get("CI"):
# We want to run it in an arbitrary directory, but the options
# are limited here... We can only install to $HOME :shrug:
Expand All @@ -186,7 +186,7 @@ def _run_installer_pkg(installer, install_dir, example_path=None):
"Export CI=1 to run it, but it will pollute your $HOME."
)
cmd = ["pkgutil", "--expand", installer, install_dir]
return _execute(cmd), install_dir
return _execute(cmd, timeout=timeout), install_dir


def _sentinel_file_checks(example_path, install_dir):
Expand All @@ -208,21 +208,22 @@ def _run_installer(
installer_input: Optional[str] = None,
check_sentinels=True,
request=None,
timeout=420,
):
if installer.suffix == ".exe":
_run_installer_exe(installer, install_dir, installer_input=installer_input)
_run_installer_exe(installer, install_dir, installer_input=installer_input, timeout=timeout)
elif installer.suffix == ".sh":
_run_installer_sh(installer, install_dir, installer_input=installer_input)
_run_installer_sh(installer, install_dir, installer_input=installer_input, timeout=timeout)
elif installer.suffix == ".pkg":
if request and ON_CI:
request.addfinalizer(lambda: shutil.rmtree(str(install_dir)))
_run_installer_pkg(installer, install_dir, example_path=example_path)
_run_installer_pkg(installer, install_dir, example_path=example_path, timeout=timeout)
else:
raise ValueError(f"Unknown installer type: {installer.suffix}")
if check_sentinels:
_sentinel_file_checks(example_path, install_dir)
if installer.suffix == ".exe":
_run_uninstaller_exe(install_dir)
_run_uninstaller_exe(install_dir, timeout=timeout)


def create_installer(
Expand All @@ -231,6 +232,7 @@ def create_installer(
conda_exe=CONSTRUCTOR_CONDA_EXE,
debug=CONSTRUCTOR_DEBUG,
with_spaces=False,
timeout=420,
**env_vars,
) -> Tuple[Path, Path]:
if sys.platform.startswith("win") and conda_exe and _is_micromamba(conda_exe):
Expand All @@ -251,7 +253,7 @@ def create_installer(
if debug:
cmd.append("--debug")

_execute(cmd, **env_vars)
_execute(cmd, timeout=timeout, **env_vars)

install_dir_prefix = "i n s t a l l" if with_spaces else "install"

Expand Down Expand Up @@ -421,7 +423,7 @@ def test_example_from_env_txt(tmp_path, request):

def test_example_from_env_yaml(tmp_path, request):
input_path = _example_path("from_env_yaml")
for installer, install_dir in create_installer(input_path, tmp_path):
for installer, install_dir in create_installer(input_path, tmp_path, timeout=600):
_run_installer(input_path, installer, install_dir, request=request)
if installer.suffix == ".pkg" and not ON_CI:
return
Expand Down

0 comments on commit fa82997

Please sign in to comment.