qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [23/50] [abbrv] qpid-proton git commit: PROTON-928: add more task cancellation tests
Date Tue, 08 Sep 2015 16:37:41 GMT
PROTON-928: add more task cancellation tests


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/ca47d726
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/ca47d726
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/ca47d726

Branch: refs/heads/proton-go
Commit: ca47d7260da1052e26cc8cac0997c6a1e491d5ef
Parents: e86cd22
Author: Bozo Dragojevic <bozzo@digiverse.si>
Authored: Thu Jul 9 11:43:51 2015 +0200
Committer: Bozo Dragojevic <bozzo@digiverse.si>
Committed: Thu Jul 9 11:43:51 2015 +0200

----------------------------------------------------------------------
 tests/python/proton_tests/reactor.py | 69 +++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ca47d726/tests/python/proton_tests/reactor.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/reactor.py b/tests/python/proton_tests/reactor.py
index 067c5c0..5734582 100644
--- a/tests/python/proton_tests/reactor.py
+++ b/tests/python/proton_tests/reactor.py
@@ -172,16 +172,79 @@ class ExceptionTest(Test):
         except Barf:
             pass
 
+    def test_schedule_many_nothings(self):
+        class Nothing:
+            results = []
+            def on_timer_task(self, event):
+                self.results.append(None)
+        num = 12345
+        for a in range(num):
+            self.reactor.schedule(0, Nothing())
+        self.reactor.run()
+        assert len(Nothing.results) == num
+
+    def test_schedule_many_nothing_refs(self):
+        class Nothing:
+            results = []
+            def on_timer_task(self, event):
+                self.results.append(None)
+        num = 12345
+        tasks = []
+        for a in range(num):
+            tasks.append(self.reactor.schedule(0, Nothing()))
+        self.reactor.run()
+        assert len(Nothing.results) == num
+
+    def test_schedule_many_nothing_refs_cancel_before_run(self):
+        class Nothing:
+            results = []
+            def on_timer_task(self, event):
+                self.results.append(None)
+        num = 12345
+        tasks = []
+        for a in range(num):
+            tasks.append(self.reactor.schedule(0, Nothing()))
+        for task in tasks:
+            task.cancel()
+        self.reactor.run()
+        assert len(Nothing.results) == 0
+
     def test_schedule_cancel(self):
         barf = self.reactor.schedule(10, BarfOnTask())
         class CancelBarf:
+            def __init__(self, barf):
+                self.barf = barf
             def on_timer_task(self, event):
-                barf.cancel()
-        self.reactor.schedule(0, CancelBarf())
+                self.barf.cancel()
+                pass
+        self.reactor.schedule(0, CancelBarf(barf))
+        now = self.reactor.mark()
+        try:
+            self.reactor.run()
+            elapsed = self.reactor.mark() - now
+            assert elapsed < 10, "expected cancelled task to not delay the reactor by
%s" % elapsed
+        except Barf:
+            assert False, "expected barf to be cancelled"
+
+    def test_schedule_cancel_many(self):
+        num = 12345
+        barfs = set()
+        for a in range(num):
+            barf = self.reactor.schedule(10*(a+1), BarfOnTask())
+            class CancelBarf:
+                def __init__(self, barf):
+                    self.barf = barf
+                def on_timer_task(self, event):
+                    self.barf.cancel()
+                    barfs.discard(self.barf)
+                    pass
+            self.reactor.schedule(0, CancelBarf(barf))
+            barfs.add(barf)
         now = self.reactor.mark()
         try:
             self.reactor.run()
             elapsed = self.reactor.mark() - now
-            assert elapsed < 10, "expected cancelled task to not delay the reactor by
" + elapsed
+            assert elapsed < num, "expected cancelled task to not delay the reactor by
%s" % elapsed
+            assert not barfs, "expected all barfs to be discarded"
         except Barf:
             assert False, "expected barf to be cancelled"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message