revamped task handler unit tests
found bug when a False persistent kwarg is passed to the add method. Resolved it.
All evennia unit tests pass. Default run level and run level 2.
Added method remove_all to task handler. (intended for unit testing)
Created a method to mimic a server restart for the purpose of task handler.
test_delay unit test passes.
Task handler will automatically remove uncalled but canceled from task handler. By default this will not occur until a canceled task has been uncalled for 60 second after the time it should have been called. To adjust this time use TASK_HANDLER.stale_timeout. If stale_timeout is 0 stale tasks will not be automatically removed.
This is not done on a timer. I is done as new tasks are added or the load method is called.
Added unit tests to test automatic removal. Including when it should not automatically removed. Both when it is too soon, or when the stale_timeout attribute is set to 0.
Created an object to represent a task.
This allows for the return of TASK_HANDLER.add or utils.delay to be an object that has callable methods. It has been created to mock the most common methods and attributes of a twisted deferred object.
Changed test_utils.test_delay for new usage.
Returned previously changed modules slow_exit, tutorial_world.objects and portal.telnet to their previous states. As the return of utils.delay can be used as if it were a deferred.
All evennia unit tests pass
TaskHandler.do_task is now state aware and can be called manually.
It can now return the callbacks returns.
added unit tests to verify early callback is functional. Both persistent and non-persistent tasks.
All evennia unit tests pass.
Created task handler methods to cancel a task and check if a task exists.
Modified unit tests to use these and test methods.
unit test test_delay passes.
TaskHandler.remove method now functions. Previous it would have removed the task from the TaskHandler.tasks dictionary, but never canceled the task. Making the "remove a persistent task without executing it" incorrect. Previous there was no method to get a persistent tasks's deferral instance, which was likely why TaskHandler.remove was not used within the module.
Added unit tests to test TaskHandler.remove
Updated task handler to only return task id.
updated code within evennia that relied on the deferral directly. Including unit test for one.
all unit tests pass.
Test server functional after restarting, no issues found would telnet web client. (delay was used in the telnet module in the portal folder.
I needed to commit this before continuing forward. There is already a high line count change.
Added an errback to handle errors within task handler's deferred instance.
Without this instances of deferred cause a traceback when a deferred is canceled without errback or callback having been called.
This traceback does not end execution, and ultimately would only show to main console.
Reference cancel: https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/defer.py
All evennia unit tests pass.
Unit test for task handler tasks that complete after delay time.
Required creating local reference for a clock.
All evennia unit tests pass with `evennia test evennia`.
All of my projects unit tests passed. They have a very heavy usage of reactor.
Verified delays working with project manually
Moving forward with creating method to call callbacks early.
Any usage of taskhandler's method outside of the deferred instance calling it results in errors.
Referencing: It's easier to access these tasks (should it be necessary) using
`evennia.scripts.taskhandler.TASK_HANDLER`
I can see it is intended to be used this way.
More importantly usage of the global reactor would require usage of reactorbuilder API which is recomended for building reactors only.
Commiting notes before switching to twisted's documented methods for making and testing deferrals.
In short I need to get an instance of reactor's callLater. Creating and working with that call later will allow me to test taskhandler and make it function as intended.
Usage of utils.delay will not change.