From 3ab226c1299da2a6187a115ff0080fe81876e9c5 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 10 Dec 2017 09:38:27 +0100 Subject: [PATCH] RSS: Only defer feed loading at plugin load while the bot is starting. Defering it if the plugin is (re)loaded while already running is useless. Closes GH-922. --- plugins/RSS/plugin.py | 5 ++++- plugins/RSS/test.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 1fe6d0ea2..fe5108f59 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -178,7 +178,10 @@ class RSS(callbacks.Plugin): self.__parent = super(RSS, self) self.__parent.__init__(irc) - self._init_time = time.time() # To delay loading the feeds + if world.starting: + self._init_time = time.time() # To delay loading the feeds + else: + self._init_time = 0 # Scheme: {name: url} self.feed_names = callbacks.CanonicalNameDict() diff --git a/plugins/RSS/test.py b/plugins/RSS/test.py index 07872a321..5b9c88fb3 100644 --- a/plugins/RSS/test.py +++ b/plugins/RSS/test.py @@ -212,14 +212,28 @@ class RSSTestCase(ChannelPluginTestCase): self.assertNotError(' ') feedparser._open_resource = constant(xkcd_new) self.assertNotError('reload RSS') - self.assertNoResponse(' ') - time.sleep(1.1) self.assertRegexp(' ', 'Telescopes') finally: self._feedMsg('rss announce remove xkcd') self._feedMsg('rss remove xkcd') feedparser._open_resource = old_open + def testReloadNoDelay(self): + # https://github.com/ProgVal/Limnoria/issues/922 + old_open = feedparser._open_resource + feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) + try: + with conf.supybot.plugins.RSS.waitPeriod.context(1): + self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') + self.assertRegexp('xkcd', 'Snake Facts') + self.assertNotError('reload RSS') + self.assertRegexp('xkcd', 'Snake Facts') + finally: + self._feedMsg('rss announce remove xkcd') + self._feedMsg('rss remove xkcd') + feedparser._open_resource = old_open + def testReannounce(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old)