Skip to content

Commit

Permalink
test: added more unit tests for scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Dec 20, 2022
1 parent 7e2db1f commit dff5165
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/colony/test/libs/scheduling_util.py
Expand Up @@ -65,7 +65,7 @@ def update_values():
self.assertNotEqual(values, dict(a = 1))

scheduler.add_callable(update_values)
time.sleep(0.5)
time.sleep(0.25)
self.assertEqual(values, dict(a = 1))

def test_stopped(self):
Expand All @@ -91,7 +91,39 @@ def update_values():
self.assertNotEqual(values, dict(a = 1))

scheduler.add_callable(update_values, verify = False)
time.sleep(0.5)
time.sleep(0.25)
self.assertNotEqual(values, dict(a = 1))

self.assert_raises(RuntimeError, scheduler.start_scheduler)

def test_exception_handler(self):
"""
Tests that the exception handler is properly handling
exceptions raised in the callable execution.
"""

scheduler = colony.Scheduler()
scheduler.start_scheduler()
self.assertEqual(scheduler.is_running(), True)
self.assertEqual(scheduler.exception_handler, None)

values = dict()

def update_values_raise():
values["a"] = 1
raise Exception()

scheduler.add_callable(update_values_raise)
time.sleep(0.25)
self.assertEqual(values, dict(a = 1))
self.assertEqual(scheduler.is_running(pedantic = True), True)

def exception_handler(callable, exception):
values["exception"] = exception.__class__

scheduler.set_exception_handler(exception_handler)

scheduler.add_callable(update_values_raise)
time.sleep(0.25)
self.assertEqual(values, dict(a = 1, exception = Exception))
self.assertEqual(scheduler.is_running(pedantic = True), True)

0 comments on commit dff5165

Please sign in to comment.