summaryrefslogtreecommitdiff
path: root/tests/glibext/workqueue.py
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-06-21 22:26:13 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-06-21 22:26:13 (GMT)
commitd49b837c891e0490167b51c4a9811cb2e8276588 (patch)
tree9bc499f2d7077a0e715b88c8c71dca1691b6c1df /tests/glibext/workqueue.py
parentfde070b3d2392333fffec6ac6eff3647dacd8b80 (diff)
Restore and improve work queues.gtk4
Diffstat (limited to 'tests/glibext/workqueue.py')
-rw-r--r--tests/glibext/workqueue.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/glibext/workqueue.py b/tests/glibext/workqueue.py
new file mode 100644
index 0000000..203970b
--- /dev/null
+++ b/tests/glibext/workqueue.py
@@ -0,0 +1,49 @@
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.glibext import GenericWork, WorkQueue
+from threading import Lock
+
+
+class TestWorks(ChrysalideTestCase):
+ """TestCase for glibext.*Work*"""
+
+ def testBasicWorkQueueBehaviour(self):
+ """Check the default basic behaviour of a work queue."""
+
+ queue = WorkQueue()
+
+ ret = queue.is_empty(123)
+ self.assertTrue(ret)
+
+
+ def testWorkScheduling(self):
+ """Check scheduled works results."""
+
+ class SchedulableWork(GenericWork):
+ def __init__(self, lck, val):
+ super(SchedulableWork, self).__init__()
+ self._lck = lck
+ self._val = val
+ def _run(self):
+ self._lck.acquire()
+ self._val['integer'] += 1
+ self._lck.release()
+
+ lock = Lock()
+ value = { 'integer': 0 }
+
+ queue = WorkQueue()
+
+ gid = queue.define_group(4)
+
+ count = 31
+
+ for i in range(count):
+
+ work = SchedulableWork(lock, value)
+ queue.schedule(work, gid)
+
+ while not(queue.wait_for_completion(gid)):
+ pass
+
+ self.assertEqual(value['integer'], count)