diff --git a/tests/test_coding/test_concurrent.py b/tests/test_coding/test_concurrent.py index 1624c67cc63d09a507307ac4da4ba1c812fff76f..49db407262c6eb812335a6b05114fe17d0ef3fb1 100644 --- a/tests/test_coding/test_concurrent.py +++ b/tests/test_coding/test_concurrent.py @@ -38,9 +38,14 @@ class TestConcurrent(unittest.TestCase): def test_bogus(self): bt = BogusTerminableThread() + self.assertFalse(bt.is_alive()) + self.assertRaises(RuntimeError, bt.join) bt.start() + self.assertRaises(RuntimeError, bt.start) self.assertRaises(WouldWaitMore, lambda: bt.join(1)) + self.assertTrue(bt.is_alive()) bt.terminate() + self.assertRaises(RuntimeError, bt.start) bt.join(2) def test_thread_collection(self): @@ -462,6 +467,21 @@ class TestConcurrent(unittest.TestCase): ml2 = copy.copy(ml) self.assertEqual(ml2, ml) + def test_terminate_on_exception(self): + class MyThread(TerminableThread): + def __init__(self): + super().__init__(terminate_on=(ValueError, KeyError)) + self.a = 0 + + def loop(self) -> None: + self.a += 1 + if self.a == 4: + raise ValueError() + + mt = MyThread() + mt.start().join() + mt.terminate() + @unittest.skipUnless(sys.implementation.name == 'cpython', 'Does not work on PyPy :(') def test_condition(self): dct = {'a': False}