[pygobject/benzea/gio-asyncio: 2/2] test




commit f6c1d465615f3385844ae2f1d929f1519e6027ed
Author: Benjamin Berg <bberg redhat com>
Date:   Wed Nov 17 21:05:28 2021 +0100

    test

 .gitlab-ci.yml       | 104 +++++++++++++++++++++++++--------------------------
 gi/events.py         |  17 +++++++++
 tests/meson.build    |   3 +-
 tests/runtests.py    |   6 +++
 tests/test_events.py |  39 +++++++++++++++++++
 5 files changed, 116 insertions(+), 53 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index de9d9b0b..ba852c19 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -52,35 +52,35 @@ pages:
   only:
     - master
 
-mingw32:
-  variables:
-    MSYSTEM: "MINGW32"
-  <<: *mingw-defaults
-
-mingw64:
-  variables:
-    MSYSTEM: "MINGW64"
-  <<: *mingw-defaults
+#mingw32:
+#  variables:
+#    MSYSTEM: "MINGW32"
+#  <<: *mingw-defaults
+#
+#mingw64:
+#  variables:
+#    MSYSTEM: "MINGW64"
+#  <<: *mingw-defaults
 
 python3.6:
   variables:
     PYENV_VERSION: "3.6.12"
   <<: *defaults
 
-python3.7:
-  variables:
-    PYENV_VERSION: "3.7.9-debug"
-  <<: *defaults
-
-python3.8:
-  variables:
-    PYENV_VERSION: "3.8.5-debug"
-  <<: *defaults
-
-python3.9:
-  variables:
-    PYENV_VERSION: "3.9.0-debug"
-  <<: *defaults
+#python3.7:
+#  variables:
+#    PYENV_VERSION: "3.7.9-debug"
+#  <<: *defaults
+#
+#python3.8:
+#  variables:
+#    PYENV_VERSION: "3.8.5-debug"
+#  <<: *defaults
+#
+#python3.9:
+#  variables:
+#    PYENV_VERSION: "3.9.0-debug"
+#  <<: *defaults
 
 pypy3.6:
   allow_failure: true
@@ -88,32 +88,32 @@ pypy3.6:
     PYENV_VERSION: "pypy3.6-7.3.1"
   <<: *defaults
 
-old-i386-py3:
-  stage: build_and_test
-  image: registry.gitlab.gnome.org/gnome/pygobject/old:v4
-  artifacts:
-    paths:
-      - coverage/
-  script:
-   - bash -x ./.gitlab-ci/test-docker-old.sh
-
-gnome-master:
-  allow_failure: true
-  stage: build_and_test
-  image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master
-  tags:
-    - flatpak
-  script:
-    - xvfb-run -a flatpak run --filesystem=host --share=network --socket=x11 --command=bash 
org.gnome.Sdk//master -x .gitlab-ci/test-flatpak.sh
-
-gnome-master-gtk4:
-  allow_failure: true
-  stage: build_and_test
-  image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master
-  tags:
-    - flatpak
-  script:
-    - xvfb-run -a flatpak run --filesystem=host --share=network --socket=x11 --command=bash 
org.gnome.Sdk//master -x .gitlab-ci/test-flatpak-gtk4.sh
-  artifacts:
-    paths:
-      - coverage/
\ No newline at end of file
+#old-i386-py3:
+#  stage: build_and_test
+#  image: registry.gitlab.gnome.org/gnome/pygobject/old:v4
+#  artifacts:
+#    paths:
+#      - coverage/
+#  script:
+#   - bash -x ./.gitlab-ci/test-docker-old.sh
+#
+#gnome-master:
+#  allow_failure: true
+#  stage: build_and_test
+#  image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master
+#  tags:
+#    - flatpak
+#  script:
+#    - xvfb-run -a flatpak run --filesystem=host --share=network --socket=x11 --command=bash 
org.gnome.Sdk//master -x .gitlab-ci/test-flatpak.sh
+#
+#gnome-master-gtk4:
+#  allow_failure: true
+#  stage: build_and_test
+#  image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master
+#  tags:
+#    - flatpak
+#  script:
+#    - xvfb-run -a flatpak run --filesystem=host --share=network --socket=x11 --command=bash 
org.gnome.Sdk//master -x .gitlab-ci/test-flatpak-gtk4.sh
+#  artifacts:
+#    paths:
+#      - coverage/
\ No newline at end of file
diff --git a/gi/events.py b/gi/events.py
index adaa8e17..8067cf05 100644
--- a/gi/events.py
+++ b/gi/events.py
@@ -94,8 +94,10 @@ class GLibEventLoop(asyncio.SelectorEventLoop):
                                finalizer=self._asyncgen_finalizer_hook)
         try:
             events._set_running_loop(self)
+            print("running mainloop")
             g_main_loop_run(self._main_loop)
         finally:
+            print("mainloop quit")
             self._context.release()
             self._thread_id = None
             events._set_running_loop(None)
@@ -104,6 +106,7 @@ class GLibEventLoop(asyncio.SelectorEventLoop):
             except AttributeError:
                 pass
             sys.set_asyncgen_hooks(*old_agen_hooks)
+        print("run_forever done")
 
     def time(self):
         return GLib.get_monotonic_time() / 1000000
@@ -122,13 +125,19 @@ class GLibEventLoop(asyncio.SelectorEventLoop):
 
     def stop(self):
         # Simply quit the mainloop
+        print("stopping")
         self._main_loop.quit()
+        print("stopped")
 
     def close(self):
         super().close()
         for s in list(self.__signal_handlers):
             self.remove_signal_handler(s)
 
+    def __del__(self, *args):
+        print("deleting", self, args)
+        super().__del__(*args)
+
     if sys.platform != "win32":
         def add_signal_handler(self, sig, callback, *args):
             """Add a handler for UNIX signal"""
@@ -332,6 +341,7 @@ class _Source(GLib.Source):
 
     def prepare(self):
         timeout = self._loop()._get_timeout_ms()
+        print("preparing with timeout", timeout)
 
         # NOTE: Always return False, FDs are queried in check and the timeout
         #       needs to be rechecked anyway.
@@ -353,17 +363,21 @@ class _Source(GLib.Source):
 
         timeout = self._loop()._get_timeout_ms()
         if timeout == 0:
+            print("check returns ready due to timeout")
             return True
 
+        print("checking with timeout", timeout)
         return bool(ready)
 
     def dispatch(self, callback, args):
+        print("dispatching")
         # Now, wag the dog by its tail
         self._dispatching = True
         try:
             self._loop()._run_once()
         finally:
             self._dispatching = False
+        print("done dispatching")
 
         return GLib.SOURCE_CONTINUE
 
@@ -429,6 +443,9 @@ class _Selector(selectors.BaseSelector):
 
         return key
 
+    def __del__(self, *args):
+        print("deleting", self, args)
+
     # We could override modify, but it is only slightly when the "events" change.
 
     def get_key(self, fileobj):
diff --git a/tests/meson.build b/tests/meson.build
index 6a25688e..ea725fc1 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -126,8 +126,9 @@ if pycairo_dep.found() and pycairo_dep.type_name() == 'internal'
 endif
 envdata.append('PYTHONPATH', python_paths)
 envdata.append('TESTS_BUILDDIR', meson.current_build_dir())
+envdata.append('PYGI_TEST_VERBOSE', '1')
 
 test('pygobject-test-suite', python,
   args : [join_paths(meson.current_source_dir(), 'runtests.py')],
   env : envdata,
-  timeout : 90)
+  timeout : 20)
diff --git a/tests/runtests.py b/tests/runtests.py
index 721b5d80..932b8cb4 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -6,6 +6,12 @@ import sys
 
 import pytest
 
+# Try to generate backtrace if meson kills as with SIGTERM:
+# will not work if the mainloop is overriding SIGTERM
+import signal
+def r(*args):
+    raise KeyboardInterrupt()
+signal.signal(signal.SIGTERM, r)
 
 def main(argv):
     if '--help' in argv:
diff --git a/tests/test_events.py b/tests/test_events.py
index dd527374..394a5430 100644
--- a/tests/test_events.py
+++ b/tests/test_events.py
@@ -26,12 +26,21 @@ except ImportError:
         warnings.warn('Upstream test_asyncio module has missing files!')
         raise unittest.SkipTest('Upstream test_asyncio module has missing files!')
 
+import os
 import sys
 import gi
 import gi.events
 import asyncio
 import threading
 
+from test import support
+from asyncio import base_events
+
+orig = base_events._run_until_complete_cb
+def wrapper(*args):
+    print("run until complete future completed", args)
+    orig(*args)
+base_events._run_until_complete_cb = wrapper
 
 # None of this currently works on Windows
 if sys.platform != 'win32':
@@ -66,12 +75,42 @@ if sys.platform != 'win32':
             asyncio.set_event_loop_policy(None)
             super().tearDownClass()
 
+        def setUp(self):
+            print("running", os.environ['PYTEST_CURRENT_TEST'])
+            super().setUp()
+
+        def tearDown(self):
+            print("tearing down")
+            asyncio.set_child_watcher(None)
+
+            # just in case if we have transport close callbacks
+            if not self.loop.is_closed():
+                test_utils.run_briefly(self.loop)
+
+            print("ran briefly if needed")
+
+            self.doCleanups()
+            print("cleanups done")
+            support.gc_collect()
+            print("gc collected")
+            test_utils.TestCase.tearDown(self)
+            print('test case tear down done')
+
         def create_event_loop(self):
             return asyncio.get_event_loop_policy().get_event_loop()
 
+        def test_run_until_complete(self):
+            t0 = self.loop.time()
+            print("running mainloop with 0.1 sleep")
+            self.loop.run_until_complete(asyncio.sleep(0.1))
+            print("done running mainloop")
+            t1 = self.loop.time()
+            self.assertTrue(0.08 <= t1-t0 <= 0.8, t1-t0)
+
     class SubprocessWatcherTests(SubprocessMixin, test_utils.TestCase):
 
         def setUp(self):
+            print("running", os.environ['PYTEST_CURRENT_TEST'])
             super().setUp()
             policy = gi.events.GLibEventLoopPolicy()
             asyncio.set_event_loop_policy(policy)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]