Add testcase for this specific memory leak
Ensure that the event scheduler shutdown removes the all references in
the ThreadedEventEmitter.
@@ -6,7 +6,10 @@ import unittest
import time
from unittest.mock import MagicMock, patch
-from mycroft.skills.event_scheduler import EventScheduler
+from mycroft.messagebus.client.threaded_event_emitter import (
+ ThreadedEventEmitter)
+from mycroft.skills.event_scheduler import (EventScheduler,
+ EventSchedulerInterface)
class TestEventScheduler(unittest.TestCase):
@@ -98,3 +101,24 @@ class TestEventScheduler(unittest.TestCase):
self.assertEquals(emitter.emit.call_args[0][0].msg_type, 'test')
self.assertEquals(emitter.emit.call_args[0][0].data, {})
es.shutdown()
+
+
+class TestEventSchedulerInterface(unittest.TestCase):
+ def test_shutdown(self):
+ def f(message):
+ print('TEST FUNC')
+
+ bus = ThreadedEventEmitter()
+
+ es = EventSchedulerInterface('tester')
+ es.set_bus(bus)
+ es.set_id('id')
+
+ # Schedule a repeating event
+ es.schedule_repeating_event(f, None, 10, name='f')
+ es.shutdown()
+
+ # Check that the reference to the function has been removed from the
+ # bus emitter
+ self.assertTrue(len(bus.wrappers) == 0)
+ self.assertTrue(len(bus._events['id:f']) == 0)
