1. Ronny Pfannschmidt
  2. greenlet-excstate

Commits

Floris Bruynooghe  committed 947d475

Extra tests for switching between multiple greenlets

Some tests to ensure multiple greenlets are used in various
configurations and that all stack switches work.

  • Participants
  • Parent commits 9827a62
  • Branches default

Comments (0)

Files changed (1)

File tests/test_greenlet.py

View file
  • Ignore whitespace
     def test_run_equals_None(self):
         g = greenlet(run=None)
 
+    def test_two_children(self):
+        lst = []
+        def f():
+            lst.append(1)
+            greenlet.getcurrent().parent.switch()
+            lst.extend([1, 1])
+        g = greenlet(f)
+        h = greenlet(f)
+        g.switch()
+        self.assertEqual(len(lst), 1)
+        h.switch()
+        self.assertEqual(len(lst), 2)
+        h.switch()
+        self.assertEqual(len(lst), 4)
+        self.assertEqual(h.dead, True)
+        g.switch()
+        self.assertEqual(len(lst), 6)
+        self.assertEqual(g.dead, True)
+
+    def test_two_recursive_children(self):
+        lst = []
+        def f():
+            lst.append(1)
+            greenlet.getcurrent().parent.switch()
+        def g():
+            lst.append(1)
+            g = greenlet(f)
+            g.switch()
+            lst.append(1)
+        g = greenlet(g)
+        g.switch()
+        self.assertEqual(len(lst), 3)
+
     def test_threads(self):
         success = []
         def f():