Open chrisjsewell opened 2 years ago
FYI, I checked this is not a tox
specific issue, i.e. the same issue is present when directly calling pytest
The first part of the problem seems to be that the particular setup takes a bit too much (more than 10 seconds) in launching a subprocess and/or loading the AiiDA profile. I will try to replace the tests that use the MockProcess
.
The second part is a bit more difficult and it might be harder to debug without access to an environment where I can reproduce it. You are running these tests inside a docker container, right? Can I get the parameters of it?
cheers
You are running these tests inside a docker container, right?
no just locally on my macbook
Uhm, ok, then I think before doing any changes to the tests it might be better to try to figure out what is happening. Because to remove the MockProcess
I would need to monkeypatch the os.getpid()
calls or something like this and might end up hiding some problem of incompatibilities that is triggering here.
Can you replace the test_access_control
function with this and run with pytest -s
?
def test_access_control(profile_access_manager):
accessing_process = MockProcess(profile_access_manager.profile)
import os
state0 = os.listdir(profile_access_manager._dirpath_records)
accessing_pid = accessing_process.start()
state1 = os.listdir(profile_access_manager._dirpath_records)
assert profile_access_manager.is_active()
accessing_process.stop()
process_file = str(accessing_pid) + '.pid'
print('\n\n')
print(os.getpid(), accessing_pid)
print(state0)
print(state1)
print(os.listdir(profile_access_manager._dirpath_records))
print('\n\n')
tracking_files = [filepath.name for filepath in profile_access_manager._get_tracking_files('.pid')]
assert process_file in tracking_files
(with also check_count == 1000
)
$ pytest tests/manage/test_profile_access.py::test_access_control
=============================================================================================== test session starts ================================================================================================
platform darwin -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /Users/chrisjsewell/Documents/GitHub/aiida_core_develop, configfile: pyproject.toml
plugins: asyncio-0.16.0, benchmark-3.4.1, datadir-1.3.1, rerunfailures-9.1.1, regressions-2.2.0, cov-2.10.1, timeout-1.4.2
collected 1 item
tests/manage/test_profile_access.py F [100%]
===================================================================================================== FAILURES =====================================================================================================
_______________________________________________________________________________________________ test_access_control ________________________________________________________________________________________________
profile_access_manager = <aiida.manage.profile_access.ProfileAccessManager object at 0x7f883b4cf670>
def test_access_control(profile_access_manager):
accessing_process = MockProcess(profile_access_manager.profile)
import os
state0 = os.listdir(profile_access_manager._dirpath_records)
accessing_pid = accessing_process.start()
state1 = os.listdir(profile_access_manager._dirpath_records)
assert profile_access_manager.is_active()
accessing_process.stop()
process_file = str(accessing_pid) + '.pid'
print('\n\n')
print(os.getpid(), accessing_pid)
print(state0)
print(state1)
print(os.listdir(profile_access_manager._dirpath_records))
print('\n\n')
tracking_files = [filepath.name for filepath in profile_access_manager._get_tracking_files('.pid')]
> assert process_file in tracking_files
E AssertionError: assert '87749.pid' in ['87502.pid', '87676.pid', '72942.pid']
tests/manage/test_profile_access.py:266: AssertionError
------------------------------------------------------------------------------------------------ Captured log setup ------------------------------------------------------------------------------------------------
DEBUG pgsu:__init__.py:141 Trying to connect via "psycopg2"...
----------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------
87676 87749
['87502.pid', '87676.pid', '72942.pid']
['87502.pid', '87676.pid', '72942.pid']
['87502.pid', '87676.pid', '72942.pid']
================================================================================================= warnings summary =================================================================================================
aiida/manage/tests/unittest_classes.py:23
/Users/chrisjsewell/Documents/GitHub/aiida_core_develop/aiida/manage/tests/unittest_classes.py:23: AiidaDeprecationWarning: This module has been deprecated and will be removed soon. Please use the `pytest` fixtures instead.
See https://github.com/aiidateam/aiida-core/wiki/AiiDA-2.0-plugin-migration-guide#unit-tests
warnings.warn( # pylint: disable=no-member
.tox/py38-pre-commit/lib/python3.8/site-packages/sphinx/util/docutils.py:45
/Users/chrisjsewell/Documents/GitHub/aiida_core_develop/.tox/py38-pre-commit/lib/python3.8/site-packages/sphinx/util/docutils.py:45: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
__version_info__ = tuple(LooseVersion(docutils.__version__).version)
.tox/py38-pre-commit/lib/python3.8/site-packages/sphinx/util/rst.py:58
/Users/chrisjsewell/Documents/GitHub/aiida_core_develop/.tox/py38-pre-commit/lib/python3.8/site-packages/sphinx/util/rst.py:58: DeprecationWarning: 'environmentfilter' is renamed to 'pass_environment', the old name will be removed in Jinja 3.1.
def heading(env: Environment, text: str, level: int = 1) -> str:
.tox/py38-pre-commit/lib/python3.8/site-packages/sphinx/jinja2glue.py:106
/Users/chrisjsewell/Documents/GitHub/aiida_core_develop/.tox/py38-pre-commit/lib/python3.8/site-packages/sphinx/jinja2glue.py:106: DeprecationWarning: 'contextfunction' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.
def warning(context: Dict, message: str, *args: Any, **kwargs: Any) -> str:
tests/manage/test_profile_access.py::test_access_control
/Users/chrisjsewell/Documents/GitHub/aiida_core_develop/aiida/manage/configuration/settings.py:61: UserWarning: Creating AiiDA configuration folder `/var/folders/t2/xbl15_3n4tsb1vr_ccmmtmbr0000gn/T/tmpw3pvw3ou/.aiida`.
warnings.warn(f'Creating AiiDA configuration folder `{path}`.')
-- Docs: https://docs.pytest.org/en/stable/warnings.html
=============================================================================================== slowest 50 durations ===============================================================================================
10.19s call tests/manage/test_profile_access.py::test_access_control
5.88s setup tests/manage/test_profile_access.py::test_access_control
0.26s teardown tests/manage/test_profile_access.py::test_access_control
============================================================================================= short test summary info ==============================================================================================
FAILED tests/manage/test_profile_access.py::test_access_control - AssertionError: assert '87749.pid' in ['87502.pid', '87676.pid', '72942.pid']
========================================================================================== 1 failed, 5 warnings in 16.73s ==========================================================================================
Mmm, moving to slack, will report back when we find the problem.
Just for reference, this is how long it is taking in my own setup:
3.90s call tests/manage/test_profile_access.py::test_lock
1.83s call tests/manage/test_profile_access.py::test_access_control
1.56s call tests/manage/test_profile_access.py::test_request_access_errors[was locked while]
1.55s call tests/manage/test_profile_access.py::test_request_access_errors[is being locked]
1.28s setup tests/manage/test_profile_access.py::test_get_tracking_files
0.02s call tests/manage/test_profile_access.py::test_get_tracking_files
0.02s call tests/manage/test_profile_access.py::test_clear_stale_pid_files
0.01s call tests/manage/test_profile_access.py::test_clear_locks
0.01s call tests/manage/test_profile_access.py::test_raise_methods
In the github machine it is taking a bit more, but it is still less than 10 seconds and it is still not the longest tests:
178.56s call tests/cmdline/commands/test_code.py::test_code_setup_local_duplicate_full_label_interactive[sleep 1; vim -cwq]
31.88s call tests/backends/aiida_sqlalchemy/migrations/test_all_basic.py::test_all_empty_migrations
22.18s call tests/cmdline/commands/test_run.py::TestAutoGroups::test_autogroup_filter_class
16.99s call tests/tools/archive/orm/test_links.py::test_high_level_workflow_links
15.66s call tests/cmdline/commands/test_data.py::TestVerdiData::test_reachable
10.16s call tests/tools/archive/orm/test_links.py::test_complex_workflow_graph_export_sets
8.57s call tests/tools/archive/orm/test_links.py::test_link_flags
7.64s call tests/cmdline/commands/test_computer.py::TestVerdiComputerConfigure::test_reachable
6.69s call tests/transports/test_all_plugins.py::TestExecuteCommandWait::test_transfer_big_stdout
6.49s call tests/test_nodes.py::TestNodeDeletion::test_delete_cases
6.17s call tests/cmdline/commands/test_code.py::test_code_setup_remote_duplicate_full_label_interactive[sleep 1; vim -cwq]
6.17s call tests/cmdline/commands/test_daemon.py::test_daemon_restart
6.15s call tests/cmdline/commands/test_computer.py::test_interactive[sleep 1; vim -cwq]
5.87s call tests/manage/test_profile_access.py::test_lock
(...)
As a recap from what we managed to figure out so far: we found that the second error was unrelated and so the only problem now is why is it taking so long to launch the subprocess (if it can do it at all). Apparently subprocess works with no problem, at least when called directly from the python interpreter, so this could be either (1) the pytest-subprocess interface acting out or (2) something else in the specific MockProcess
class gets triggered in OSX.
For testing (1) I already sent you a script via slack that you could try running on pytest to see if it still has problems without the class. For testing (2), you could try to put the following script in the aiida-core/tests/manage
folder and run it with verdi run
to see if it raises:
import test_profile_access
from aiida.manage.manager import get_manager
aiida_profile = get_manager().get_profile()
test_process = test_profile_access.MockProcess(aiida_profile)
process_id = test_process.start()
print(f'Now running process {process_id}')
test_process.stop()
Let me know how it goes.
@ramirezfranciscof do you want to close https://github.com/aiidateam/aiida-core/pull/5325 and create your own, so we can see if it is replicate with macos on the CI?
Yes sure, I could try that, I may have a bit more time after thursday to start on this. I have never created any CI workflow before so I may have to bother you with some questions, but I would welcome the exercise.
yeh no worries 👍
With current
develop
, I consistently get:If I I change
check_count == 100
tocheck_count == 1000
, the I get: