summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2013-05-08 15:24:44 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-05-10 00:36:32 +0900
commit5003c1634c48e0faca2c351ee61d2594ecd5bb9c (patch)
treed37701c17f615bf2a8a08ed96184a3001c9dfa95
parent47bc96ef98bc0f4e0fc6d1b521aff8120aeba5d1 (diff)
hub: add some more tests
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/unit/lib/test_hub.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/ryu/tests/unit/lib/test_hub.py b/ryu/tests/unit/lib/test_hub.py
index 4c558022..ffa70545 100644
--- a/ryu/tests/unit/lib/test_hub.py
+++ b/ryu/tests/unit/lib/test_hub.py
@@ -186,6 +186,48 @@ class Test_hub(unittest.TestCase):
hub.joinall(threads)
assert len(result) == 0
+ def test_spawn_kill_nowait_joinall(self):
+ # XXX this test relies on the scheduling behaviour.
+ # the intention here is, killing threads before they get active.
+
+ def _child(result):
+ result.append(1)
+
+ threads = []
+ result = []
+ with hub.Timeout(2):
+ threads.append(hub.spawn(_child, result))
+ for t in threads:
+ hub.kill(t)
+ hub.joinall(threads)
+ assert len(result) == 0
+
+ def test_spawn_kill_die_joinall(self):
+ def _child(result):
+ result.append(1)
+
+ threads = []
+ result = []
+ with hub.Timeout(2):
+ threads.append(hub.spawn(_child, result))
+ threads.append(hub.spawn(_child, result))
+ hub.sleep(0.5)
+ for t in threads:
+ hub.kill(t)
+ hub.joinall(threads)
+ assert len(result) == 2
+
+ def test_spawn_exception_joinall(self):
+ def _child():
+ raise Exception("hoge")
+
+ threads = []
+ with hub.Timeout(2):
+ threads.append(hub.spawn(_child))
+ threads.append(hub.spawn(_child))
+ hub.sleep(0.5)
+ hub.joinall(threads)
+
def test_event1(self):
ev = hub.Event()
ev.set()