test: Make assertNoResponse default to a non-zero timeout for threaded plugins.

Else it doesn't reliably check there is no response.
This commit is contained in:
Valentin Lorentz 2020-04-11 00:17:16 +02:00
parent 7e48ba0ba8
commit 2953126fca
3 changed files with 22 additions and 4 deletions

View File

@ -63,6 +63,9 @@ def constant(content):
url = 'http://www.advogato.org/rss/articles.xml'
class RSSTestCase(ChannelPluginTestCase):
plugins = ('RSS','Plugin')
timeout = 1
def testRssAddBadName(self):
self.assertError('rss add "foo bar" %s' % url)
@ -340,6 +343,8 @@ class RSSTestCase(ChannelPluginTestCase):
feedparser._open_resource = old_open
if network:
timeout = 5 # Note this applies also to the above tests
def testRssinfo(self):
timeFastForward(1.1)
self.assertNotError('rss info %s' % url)

View File

@ -42,7 +42,7 @@ class SedRegexTestCase(ChannelPluginTestCase):
# getMsg() stalls if no message is ever sent (i.e. if the plugin fails to respond to a request)
# We should limit the timeout to prevent the tests from taking forever.
timeout = 3
timeout = 1
def testSimpleReplace(self):
self.feedMsg('Abcd abcdefgh')

View File

@ -196,8 +196,10 @@ class PluginTestCase(SupyTestCase):
cleanConfDir = True
cleanDataDir = True
config = {}
timeout = None
def __init__(self, methodName='runTest'):
self.timeout = timeout
if self.timeout is None:
self.timeout = timeout
originalRunTest = getattr(self, methodName)
def runTest(self):
run = True
@ -373,12 +375,23 @@ class PluginTestCase(SupyTestCase):
'%s is not the help (%s)' % (m.args[1], lastGetHelp))
return m
def assertNoResponse(self, query, timeout=0, **kwargs):
def assertNoResponse(self, query, timeout=None, **kwargs):
if timeout is None:
timeout = 0
# timeout=0 does not wait at all for an answer after the command
# function finished running. This is fine for non-threaded
# plugins because they usually won't answer anything after that;
# but not for threaded plugins.
# TODO: also detect threaded commands
for cb in self.irc.callbacks:
if cb.threaded:
timeout = self.timeout
break
m = self._feedMsg(query, timeout=timeout, **kwargs)
self.assertFalse(m, 'Unexpected response: %r' % m)
return m
def assertSnarfNoResponse(self, query, timeout=0, **kwargs):
def assertSnarfNoResponse(self, query, timeout=None, **kwargs):
return self.assertNoResponse(query, timeout=timeout,
usePrefixChar=False, **kwargs)