diff options
author | Christoph Reiter <creiter@src.gnome.org> | 2017-03-21 12:48:27 +0100 |
---|---|---|
committer | Christoph Reiter <creiter@src.gnome.org> | 2017-03-27 16:27:00 +0200 |
commit | f47027d6abde392fff03ce9b49e42a0c6f7d83cd (patch) | |
tree | 3b71d0c0f57741773d79aaee13334041bb02f851 /tests/test_thread.py | |
parent | ab574b6c40b6e58f396c9522be864a78478617c1 (diff) | |
download | pygobject-f47027d6abde392fff03ce9b49e42a0c6f7d83cd.tar.gz |
tests: Reduce usage of timeout_add() and sleep()
* Instead of waiting for a fixed time, use a timeout and stop the main
loop right after the test has succeeded.
* Replace time.sleep to sync processes with os.pipe communication
* Chain idle sources instead of using multiple timeout sources
* Replace sleeps with unbufferd communication
https://bugzilla.gnome.org/show_bug.cgi?id=698548
Diffstat (limited to 'tests/test_thread.py')
-rw-r--r-- | tests/test_thread.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/tests/test_thread.py b/tests/test_thread.py index 3d0557e6..3da3310e 100644 --- a/tests/test_thread.py +++ b/tests/test_thread.py @@ -9,11 +9,14 @@ from gi.repository import GLib class TestThread(unittest.TestCase): def setUp(self): self.main = GLib.MainLoop() + self.called = False def from_thread_cb(self, test, enum): assert test == self.obj assert int(enum) == 0 assert type(enum) != int + self.called = True + GLib.idle_add(self.timeout_cb) def idle_cb(self): self.obj = testhelper.get_test_thread() @@ -22,8 +25,9 @@ class TestThread(unittest.TestCase): def test_extension_module(self): GLib.idle_add(self.idle_cb) - GLib.timeout_add(50, self.timeout_cb) + GLib.timeout_add(2000, self.timeout_cb) self.main.run() + self.assertTrue(self.called) def timeout_cb(self): self.main.quit() |