diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 41c657070..65716decd 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -52,6 +52,11 @@ import supybot.callbacks as callbacks from supybot.i18n import PluginInternationalization, internationalizeDocstring _ = PluginInternationalization('RSS') +if world.testing: + INIT_DELAY = 1 +else: + INIT_DELAY = 10 + if minisix.PY2: from urllib2 import ProxyHandler else: @@ -101,7 +106,7 @@ class Feed: self.data = None # We don't want to fetch feeds right after the plugin is # loaded (the bot could be starting, and thus already busy) - self.last_update = time.time() if plugin_is_loading else 0 + self.last_update = 0 self.entries = [] self.etag = None self.modified = None @@ -172,6 +177,9 @@ class RSS(callbacks.Plugin): def __init__(self, irc): self.__parent = super(RSS, self) self.__parent.__init__(irc) + + self._init_time = time.time() # To delay loading the feeds + # Scheme: {name: url} self.feed_names = callbacks.CanonicalNameDict() # Scheme: {url: feed} @@ -314,16 +322,9 @@ class RSS(callbacks.Plugin): (initial, feed.initial) = (feed.initial, False) self.announce_feed(feed, initial) - def update_feed_in_thread(self, feed): - feed.last_update = time.time() - t = world.SupyThread(target=self.update_feed, - name=format('Fetching feed %u', feed.url), - args=(feed,)) - t.setDaemon(True) - t.start() - def update_feed_if_needed(self, feed): - if self.is_expired(feed): + if self.is_expired(feed) and \ + self._init_time + INIT_DELAY < time.time(): self.update_feed(feed) @only_one_at_once diff --git a/plugins/RSS/test.py b/plugins/RSS/test.py index ffe19e074..a3d381f5a 100644 --- a/plugins/RSS/test.py +++ b/plugins/RSS/test.py @@ -72,6 +72,7 @@ class RSSTestCase(ChannelPluginTestCase): def testInitialAnnounceNewest(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_new) + time.sleep(1.1) try: with conf.supybot.plugins.RSS.sortFeedItems.context('newestFirst'): with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(1): @@ -86,6 +87,7 @@ class RSSTestCase(ChannelPluginTestCase): def testInitialAnnounceOldest(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_new) + time.sleep(1.1) try: with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(1): with conf.supybot.plugins.RSS.sortFeedItems.context('oldestFirst'): @@ -100,6 +102,7 @@ class RSSTestCase(ChannelPluginTestCase): def testNoInitialAnnounce(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) try: with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(0): self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') @@ -113,6 +116,7 @@ class RSSTestCase(ChannelPluginTestCase): def testAnnounce(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) try: self.assertError('rss announce add xkcd') self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') @@ -137,6 +141,7 @@ class RSSTestCase(ChannelPluginTestCase): def testMaxAnnounces(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) try: self.assertError('rss announce add xkcd') self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') @@ -161,6 +166,7 @@ class RSSTestCase(ChannelPluginTestCase): def testAnnounceAnonymous(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) try: self.assertNotError('rss announce add http://xkcd.com/rss.xml') self.assertNotError(' ') @@ -180,6 +186,7 @@ class RSSTestCase(ChannelPluginTestCase): def testAnnounceReload(self): 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') @@ -194,14 +201,34 @@ class RSSTestCase(ChannelPluginTestCase): self._feedMsg('rss remove xkcd') feedparser._open_resource = old_open - def tesReannounce(self): + def testReload(self): 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.assertNotError('rss announce add xkcd') + 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 testReannounce(self): + old_open = feedparser._open_resource + feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) try: self.assertError('rss announce add xkcd') self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') self.assertNotError('rss announce add xkcd') - self.assertNotError(' ') + self.assertRegexp(' ', 'Snake Facts') with conf.supybot.plugins.RSS.waitPeriod.context(1): with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(1): with conf.supybot.plugins.RSS.sortFeedItems.context('oldestFirst'): @@ -216,6 +243,7 @@ class RSSTestCase(ChannelPluginTestCase): self.assertNotError('rss announce add xkcd') self.assertNoResponse(' ') time.sleep(1.1) + self.assertRegexp(' ', 'Chaos') self.assertRegexp(' ', 'Telescopes') self.assertNoResponse(' ') finally: @@ -226,6 +254,7 @@ class RSSTestCase(ChannelPluginTestCase): def testFeedSpecificFormat(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) try: self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') self.assertNotError('rss add xkcdsec https://xkcd.com/rss.xml') @@ -241,6 +270,7 @@ class RSSTestCase(ChannelPluginTestCase): def testFeedSpecificWaitPeriod(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old) + time.sleep(1.1) try: self.assertNotError('rss add xkcd1 http://xkcd.com/rss.xml') self.assertNotError('rss announce add xkcd1') @@ -269,6 +299,7 @@ class RSSTestCase(ChannelPluginTestCase): feedparser._open_resource = old_open def testDescription(self): + time.sleep(1.1) with conf.supybot.plugins.RSS.format.context('$description'): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_new) @@ -280,6 +311,7 @@ class RSSTestCase(ChannelPluginTestCase): if network: def testRssinfo(self): + time.sleep(1.1) self.assertNotError('rss info %s' % url) self.assertNotError('rss add advogato %s' % url) self.assertNotError('rss info advogato') @@ -287,10 +319,12 @@ class RSSTestCase(ChannelPluginTestCase): self.assertNotError('rss remove advogato') def testRssinfoDoesTimeProperly(self): + time.sleep(1.1) self.assertNotRegexp('rss info http://slashdot.org/slashdot.rss', '-1 years') def testAnnounceAdd(self): + time.sleep(1.1) self.assertNotError('rss add advogato %s' % url) self.assertNotError('rss announce add advogato') self.assertNotRegexp('rss announce', r'ValueError') @@ -298,11 +332,13 @@ class RSSTestCase(ChannelPluginTestCase): self.assertNotError('rss remove advogato') def testRss(self): + time.sleep(1.1) self.assertNotError('rss %s' % url) m = self.assertNotError('rss %s 2' % url) self.failUnless(m.args[1].count(' | ') == 1) def testRssAdd(self): + time.sleep(1.1) self.assertNotError('rss add advogato %s' % url) self.assertNotError('advogato') self.assertNotError('rss advogato') @@ -312,6 +348,7 @@ class RSSTestCase(ChannelPluginTestCase): self.assertError('rss advogato') def testNonAsciiFeeds(self): + time.sleep(1.1) self.assertNotError('rss http://www.heise.de/newsticker/heise.rdf') self.assertNotError('rss info http://br-linux.org/main/index.xml')