You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:25:45 UTC

[buildstream] 02/11: _fixtures.py: Only get the normal number of threads at the start of session

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch bschubert/no-multiprocessing-bak
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 4c03165bae69a027bd81bffe5fb33e03caa64cdf
Author: Benjamin Schubert <co...@benschubert.me>
AuthorDate: Fri Jul 3 12:47:14 2020 +0000

    _fixtures.py: Only get the normal number of threads at the start of session
    
    This ensures that we also have our tests correctly shutting down
    background threads and not interferring with each other
---
 src/buildstream/testing/_fixtures.py             | 17 ++++++++++++-----
 src/buildstream/testing/_sourcetests/conftest.py |  2 +-
 tests/conftest.py                                |  6 +++++-
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/buildstream/testing/_fixtures.py b/src/buildstream/testing/_fixtures.py
index 5da51bb..5d1c1d2 100644
--- a/src/buildstream/testing/_fixtures.py
+++ b/src/buildstream/testing/_fixtures.py
@@ -14,19 +14,26 @@
 #  You should have received a copy of the GNU Lesser General Public
 #  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 
+# pylint: disable=redefined-outer-name
+
 import psutil
 import pytest
 
-from buildstream import node, utils
+from buildstream import node, utils, DownloadableFileSource
 
-# Catch tests that don't shut down background threads, which could then lead
-# to other tests hanging when BuildStream uses fork().
-@pytest.fixture(autouse=True)
-def thread_check():
+
+@pytest.fixture(autouse=True, scope="session")
+def default_thread_number():
     # xdist/execnet has its own helper thread.
     # Ignore that for `utils._is_single_threaded` checks.
     utils._INITIAL_NUM_THREADS_IN_MAIN_PROCESS = psutil.Process().num_threads()
 
+
+# Catch tests that don't shut down background threads, which could then lead
+# to other tests hanging when BuildStream uses fork().
+@pytest.fixture(autouse=True)
+def thread_check(default_thread_number):
+    assert utils._is_single_threaded()
     yield
     assert utils._is_single_threaded()
 
diff --git a/src/buildstream/testing/_sourcetests/conftest.py b/src/buildstream/testing/_sourcetests/conftest.py
index 64dd404..6790712 100644
--- a/src/buildstream/testing/_sourcetests/conftest.py
+++ b/src/buildstream/testing/_sourcetests/conftest.py
@@ -14,4 +14,4 @@
 #  You should have received a copy of the GNU Lesser General Public
 #  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 
-from .._fixtures import reset_global_node_state, thread_check  # pylint: disable=unused-import
+from .._fixtures import reset_global_node_state, default_thread_number, thread_check  # pylint: disable=unused-import
diff --git a/tests/conftest.py b/tests/conftest.py
index bb4611a..1faa4ce 100755
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -25,7 +25,11 @@ import pkg_resources
 import pytest
 
 from buildstream.testing import register_repo_kind, sourcetests_collection_hook
-from buildstream.testing._fixtures import reset_global_node_state, thread_check  # pylint: disable=unused-import
+from buildstream.testing._fixtures import (  # pylint: disable=unused-import
+    default_thread_number,
+    reset_global_node_state,
+    thread_check,
+)
 from buildstream.testing.integration import integration_cache  # pylint: disable=unused-import