Beispiel #1
0
 def test_disable_stale_removal(self):
     # manual removal of stale tasks.
     timedelay = self.timedelay
     _TASK_HANDLER.stale_timeout = 0
     for pers in (False, True):
         t = utils.delay(timedelay, dummy_func, self.char1.dbref, persistent=pers)
         t.cancel()
         self.assertFalse(t.active())
         _TASK_HANDLER.clock.advance(timedelay)  # make time pass
         if pers:
             self.assertTrue(t.get_id() in _TASK_HANDLER.to_save)
         self.assertTrue(t.get_id() in _TASK_HANDLER.tasks)
         # Make task handler's now time, after the stale timeout
         _TASK_HANDLER._now = datetime.now() + timedelta(seconds=_TASK_HANDLER.stale_timeout + timedelay + 1)
         t2 = utils.delay(timedelay, dummy_func, self.char1.dbref)
         if pers:
             self.assertTrue(t.get_id() in _TASK_HANDLER.to_save)
         self.assertTrue(t.get_id() in _TASK_HANDLER.tasks)
         self.assertEqual(self.char1.ndb.dummy_var, False)
         # manual removal should still work
         _TASK_HANDLER.clean_stale_tasks()  # cleanup of stale tasks in in the save method
         if pers:
             self.assertFalse(t.get_id() in _TASK_HANDLER.to_save)
         self.assertFalse(t.get_id() in _TASK_HANDLER.tasks)
         _TASK_HANDLER.clear()
Beispiel #2
0
 def test_server_restart(self):
     # emulate a server restart
     timedelay = self.timedelay
     utils.delay(timedelay, dummy_func, self.char1.dbref, persistent=True)
     _TASK_HANDLER.clear(False)  # remove all tasks from task handler, do not save this change.
     _TASK_HANDLER.clock.advance(timedelay)  # advance twisted reactor time past callback time
     self.assertEqual(self.char1.ndb.dummy_var, False)  # task has not run
     _TASK_HANDLER.load()  # load persistent tasks from database.
     _TASK_HANDLER.create_delays()  # create new deffered instances from persistent tasks
     _TASK_HANDLER.clock.advance(timedelay)  # Clock must advance to trigger, even if past timedelay
     self.assertEqual(self.char1.ndb.dummy_var, 'dummy_func ran')
Beispiel #3
0
 def test_auto_stale_task_removal(self):
     # automated removal of stale tasks.
     timedelay = self.timedelay
     for pers in (False, True):
         t = utils.delay(timedelay, dummy_func, self.char1.dbref, persistent=pers)
         t.cancel()
         self.assertFalse(t.active())
         _TASK_HANDLER.clock.advance(timedelay)  # make time pass
         if pers:
             self.assertTrue(t.get_id() in _TASK_HANDLER.to_save)
         self.assertTrue(t.get_id() in _TASK_HANDLER.tasks)
         # Make task handler's now time, after the stale timeout
         _TASK_HANDLER._now = datetime.now() + timedelta(seconds=_TASK_HANDLER.stale_timeout + timedelay + 1)
         # add a task to test automatic removal
         t2 = utils.delay(timedelay, dummy_func, self.char1.dbref)
         if pers:
             self.assertFalse(t.get_id() in _TASK_HANDLER.to_save)
         self.assertFalse(t.get_id() in _TASK_HANDLER.tasks)
         self.assertEqual(self.char1.ndb.dummy_var, False)
         _TASK_HANDLER.clear()
Beispiel #4
0
 def tearDown(self):
     super().tearDown()
     _TASK_HANDLER.clear()