From 5003c1634c48e0faca2c351ee61d2594ecd5bb9c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 8 May 2013 15:24:44 +0900 Subject: [PATCH] hub: add some more tests Signed-off-by: YAMAMOTO Takashi Signed-off-by: FUJITA Tomonori --- ryu/tests/unit/lib/test_hub.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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()