diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2013-05-08 15:24:44 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-05-10 00:36:32 +0900 |
commit | 5003c1634c48e0faca2c351ee61d2594ecd5bb9c (patch) | |
tree | d37701c17f615bf2a8a08ed96184a3001c9dfa95 | |
parent | 47bc96ef98bc0f4e0fc6d1b521aff8120aeba5d1 (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.py | 42 |
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() |