Add unit test for TickerHandler store_key fix

This commit is contained in:
Griatch 2025-04-26 11:51:13 +02:00
parent 43d1a36203
commit a89c8f68cd
3 changed files with 23 additions and 3 deletions

View file

@ -40,6 +40,8 @@ This upgrade requires running `evennia migrate` on your existing database
- [Fix][pull3744]: Fix for format strings not getting picked up in i18n (JohnFi)
- [Fix][pull3743]: Log full stack trace on failed object creation (aMiss-aWry)
- [Fix][pull3747]: TutorialWorld bridge-room didn't correctly randomize weather effects (SpyrosRoum)
- [Fix][pull3765]: Storing TickerHandler `store_key` in a db attribute would not
work correctly (0xDEADFED5)
- Fix: `options` setting `NOPROMPTGOAHEAD` was not possible to set (Griatch)
- Fix: Make `\\` properly preserve one backlash in funcparser (Griatch)
- Fix: The testing 'echo' inputfunc didn't work correctly; now returns both args/kwargs (Griatch)
@ -70,6 +72,7 @@ This upgrade requires running `evennia migrate` on your existing database
[pull3743]: https://github.com/evennia/evennia/pull/3743
[pull3744]: https://github.com/evennia/evennia/pull/3744
[pull3747]: https://github.com/evennia/evennia/pull/3747
[pull3765]: https://github.com/evennia/evennia/pull/3765
[issue3688]: https://github.com/evennia/evennia/issues/3688
[issue3687]: https://github.com/evennia/evennia/issues/3687

View file

@ -45,6 +45,20 @@ class TestTickerHandler(TestCase):
th = TickerHandler()
th.remove(callback=1)
def test_removing_ticker_using_store_key_in_attribute(self):
"""
Test adding a ticker, storing the store_key in an attribute, and then removing it
using that same store_key.
https://github.com/evennia/evennia/pull/3765
"""
obj = DefaultObject.create("test_object")[0]
th = TickerHandler()
obj.db.ticker = th.add(60, obj.msg, idstring="ticker_test", persistent=True)
self.assertTrue(len(th.all()), 1)
th.remove(store_key=obj.db.ticker)
self.assertTrue(len(th.all()), 0)
class TestScriptDBManager(TestCase):
"""Test the ScriptDBManger class"""

View file

@ -69,13 +69,12 @@ call the handler's `save()` and `restore()` methods when the server reboots.
import inspect
from django.core.exceptions import ObjectDoesNotExist
from twisted.internet.defer import inlineCallbacks
from evennia.scripts.scripts import ExtendedLoopingCall
from evennia.server.models import ServerConfig
from evennia.utils import inherits_from, variable_from_module
from evennia.utils.dbserialize import dbserialize, dbunserialize, pack_dbobj
from evennia.utils.logger import log_err, log_trace
from twisted.internet.defer import inlineCallbacks
_GA = object.__getattribute__
_SA = object.__setattr__
@ -566,8 +565,12 @@ class TickerHandler(object):
store_key = self._store_key(obj, path, interval, callfunc, idstring, persistent)
else:
if isinstance(store_key, tuple) and not isinstance(store_key[0], tuple):
# this means the store-key was deserialized, which means we need to
# re-build the key anew (since the obj would already be unpacked otherwise)
obj, path, callfunc = self._get_callback(getattr(store_key[0], store_key[1]))
store_key = self._store_key(obj, path, store_key[3], callfunc, store_key[4], store_key[5])
store_key = self._store_key(
obj, path, store_key[3], callfunc, store_key[4], store_key[5]
)
to_remove = self.ticker_storage.pop(store_key, None)
if to_remove:
self.ticker_pool.remove(store_key)