-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
eb6e1b4
commit 9b82abd
Showing
5 changed files
with
31 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,52 @@ | ||
"""Test container initialization.""" | ||
import psutil, os | ||
|
||
import os | ||
|
||
import psutil | ||
|
||
|
||
def test_file_descriptor_closed(aiida_profile): | ||
"""Checks if the number of open file descriptors change during a reset.""" | ||
|
||
def list_open_file_descriptors(): | ||
process = psutil.Process(os.getpid()) | ||
return process.open_files() | ||
|
||
# We have some connections active due to aiida profile during the first | ||
# reset these are destroyed. We check the second time changes the number of | ||
# open file descriptors. | ||
from aiida.manage import get_manager | ||
|
||
storage_backend = get_manager().get_profile_storage() | ||
migrator_context = storage_backend.migrator_context | ||
migrator_context = storage_backend.migrator_context | ||
open_file_descriptors_before = list_open_file_descriptors() | ||
with migrator_context(aiida_profile) as migrator: | ||
migrator.initialise_repository() | ||
migrator.reset_repository() | ||
open_file_descriptors_after = list_open_file_descriptors() | ||
assert len(open_file_descriptors_before) == len(open_file_descriptors_after), f"Before these file descriptor were open:\n{open_file_descriptors_before}\n Now these are open:\n{open_file_descriptors_after}" | ||
assert ( | ||
len(open_file_descriptors_before) == len(open_file_descriptors_after) | ||
), f'Before these file descriptor were open:\n{open_file_descriptors_before}\n Now these are open:\n{open_file_descriptors_after}' | ||
|
||
|
||
# PR COMMENT this is just a sanity check for me, I don' think that the test should be included in final PR | ||
def test_reset_storage_file_descriptor_closed(aiida_profile): | ||
"""Checks if the number of open file descriptors change during a reset.""" | ||
|
||
def list_open_file_descriptors(): | ||
process = psutil.Process(os.getpid()) | ||
return process.open_files() | ||
|
||
# We have some connections active due to aiida profile during the first | ||
# reset these are destroyed. We check the second time changes the number of | ||
# open file descriptors. | ||
# TODO The fix should keep the existing connections alive and just reuse them | ||
# then one does not need to do two resets. | ||
from aiida.manage import get_manager | ||
aiida_profile.reset_storage() | ||
|
||
aiida_profile.reset_storage() | ||
open_file_descriptors_before = list_open_file_descriptors() | ||
aiida_profile.reset_storage() | ||
aiida_profile.reset_storage() | ||
open_file_descriptors_after = list_open_file_descriptors() | ||
assert len(open_file_descriptors_before) == len(open_file_descriptors_after), f"Before these file descriptor were open:\n{open_file_descriptors_before}\n Now these are open:\n{open_file_descriptors_after}" | ||
assert ( | ||
len(open_file_descriptors_before) == len(open_file_descriptors_after) | ||
), f'Before these file descriptor were open:\n{open_file_descriptors_before}\n Now these are open:\n{open_file_descriptors_after}' |