mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
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:
parent
7e48ba0ba8
commit
2953126fca
@ -63,6 +63,9 @@ def constant(content):
|
|||||||
url = 'http://www.advogato.org/rss/articles.xml'
|
url = 'http://www.advogato.org/rss/articles.xml'
|
||||||
class RSSTestCase(ChannelPluginTestCase):
|
class RSSTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('RSS','Plugin')
|
plugins = ('RSS','Plugin')
|
||||||
|
|
||||||
|
timeout = 1
|
||||||
|
|
||||||
def testRssAddBadName(self):
|
def testRssAddBadName(self):
|
||||||
self.assertError('rss add "foo bar" %s' % url)
|
self.assertError('rss add "foo bar" %s' % url)
|
||||||
|
|
||||||
@ -340,6 +343,8 @@ class RSSTestCase(ChannelPluginTestCase):
|
|||||||
feedparser._open_resource = old_open
|
feedparser._open_resource = old_open
|
||||||
|
|
||||||
if network:
|
if network:
|
||||||
|
timeout = 5 # Note this applies also to the above tests
|
||||||
|
|
||||||
def testRssinfo(self):
|
def testRssinfo(self):
|
||||||
timeFastForward(1.1)
|
timeFastForward(1.1)
|
||||||
self.assertNotError('rss info %s' % url)
|
self.assertNotError('rss info %s' % url)
|
||||||
|
@ -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)
|
# 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.
|
# We should limit the timeout to prevent the tests from taking forever.
|
||||||
timeout = 3
|
timeout = 1
|
||||||
|
|
||||||
def testSimpleReplace(self):
|
def testSimpleReplace(self):
|
||||||
self.feedMsg('Abcd abcdefgh')
|
self.feedMsg('Abcd abcdefgh')
|
||||||
|
17
src/test.py
17
src/test.py
@ -196,7 +196,9 @@ class PluginTestCase(SupyTestCase):
|
|||||||
cleanConfDir = True
|
cleanConfDir = True
|
||||||
cleanDataDir = True
|
cleanDataDir = True
|
||||||
config = {}
|
config = {}
|
||||||
|
timeout = None
|
||||||
def __init__(self, methodName='runTest'):
|
def __init__(self, methodName='runTest'):
|
||||||
|
if self.timeout is None:
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
originalRunTest = getattr(self, methodName)
|
originalRunTest = getattr(self, methodName)
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
@ -373,12 +375,23 @@ class PluginTestCase(SupyTestCase):
|
|||||||
'%s is not the help (%s)' % (m.args[1], lastGetHelp))
|
'%s is not the help (%s)' % (m.args[1], lastGetHelp))
|
||||||
return m
|
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)
|
m = self._feedMsg(query, timeout=timeout, **kwargs)
|
||||||
self.assertFalse(m, 'Unexpected response: %r' % m)
|
self.assertFalse(m, 'Unexpected response: %r' % m)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def assertSnarfNoResponse(self, query, timeout=0, **kwargs):
|
def assertSnarfNoResponse(self, query, timeout=None, **kwargs):
|
||||||
return self.assertNoResponse(query, timeout=timeout,
|
return self.assertNoResponse(query, timeout=timeout,
|
||||||
usePrefixChar=False, **kwargs)
|
usePrefixChar=False, **kwargs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user