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.
This commit is contained in:
Valentin Lorentz 2017-12-10 09:38:27 +01:00
parent bdd0adfef5
commit 3ab226c129
2 changed files with 20 additions and 3 deletions

View File

@ -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()

View File

@ -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)