summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2019-11-13 23:17:01 +0100
committerlouiz’ <louiz@louiz.org>2019-11-13 23:23:13 +0100
commit440e04c6ba1dfae2d6fbb55b120763e3d0da6cd1 (patch)
treee139065611dd9b98612d3ab94b8e6953ec377a05 /tests
parent0cb62d993b43dd048b93e130d96c7757cf10b6d2 (diff)
downloadbiboumi-440e04c6ba1dfae2d6fbb55b120763e3d0da6cd1.tar.gz
biboumi-440e04c6ba1dfae2d6fbb55b120763e3d0da6cd1.tar.bz2
biboumi-440e04c6ba1dfae2d6fbb55b120763e3d0da6cd1.tar.xz
biboumi-440e04c6ba1dfae2d6fbb55b120763e3d0da6cd1.zip
e2e: Add a 10s timeout for expect_stanza
Otherwise, if we expect a stanza and biboumi never sends it, we just hang here. Now, we display a nice error after 10 seconds, and move on to the next test, as other failures (xpath doesn’t match) do
Diffstat (limited to 'tests')
-rw-r--r--tests/end_to_end/__main__.py11
-rw-r--r--tests/end_to_end/functions.py5
2 files changed, 15 insertions, 1 deletions
diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py
index e85a4f2..cef554e 100644
--- a/tests/end_to_end/__main__.py
+++ b/tests/end_to_end/__main__.py
@@ -83,6 +83,7 @@ class XMPPComponent(slixmpp.BaseXMPP):
self.scenario = scenario
self.biboumi = biboumi
+ self.timeout_handler = None
# A callable, taking a stanza as argument and raising a StanzaError
# exception if the test should fail.
self.stanza_checker = None
@@ -96,6 +97,13 @@ class XMPPComponent(slixmpp.BaseXMPP):
self.scenario.steps = []
self.failed = True
+ def on_timeout(self, xpaths):
+ error_msg = "Timeout while waiting for a stanza that would match the expected xpath(s):"
+ for xpath in xpaths:
+ error_msg += "\n" + xpath
+ self.error(error_msg)
+ self.run_scenario()
+
def on_end_session(self, _):
self.loop.stop()
@@ -113,6 +121,9 @@ class XMPPComponent(slixmpp.BaseXMPP):
self.run_scenario()
def run_scenario(self):
+ if self.timeout_handler is not None:
+ self.timeout_handler.cancel()
+ self.timeout_handler = None
if self.scenario.steps:
step = self.scenario.steps.pop(0)
try:
diff --git a/tests/end_to_end/functions.py b/tests/end_to_end/functions.py
index 176dca5..97cdfb0 100644
--- a/tests/end_to_end/functions.py
+++ b/tests/end_to_end/functions.py
@@ -127,7 +127,9 @@ def expect_stanza(*args, optional=False, after=None):
replacements = common_replacements
replacements.update(xmpp.saved_values)
check_func = check_xpath if not optional else check_xpath_optional
- xmpp.stanza_checker = partial(check_func, [xpath.format_map(replacements) for xpath in xpaths], xmpp, after)
+ formatted_xpaths = [xpath.format_map(replacements) for xpath in xpaths]
+ xmpp.stanza_checker = partial(check_func, formatted_xpaths, xmpp, after)
+ xmpp.timeout_handler = asyncio.get_event_loop().call_later(10, partial(xmpp.on_timeout, formatted_xpaths))
return partial(f, *args, optional=optional, after=after)
def send_stanza(stanza):
@@ -148,6 +150,7 @@ def expect_unordered(*args):
formatted_xpaths.append(formatted_xpath)
formatted_list_of_xpaths.append(tuple(formatted_xpaths))
expect_unordered_already_formatted(formatted_list_of_xpaths, xmpp, biboumi)
+ xmpp.timeout_handler = asyncio.get_event_loop().call_later(10, partial(xmpp.on_timeout, formatted_list_of_xpaths))
return partial(f, *args)
def expect_unordered_already_formatted(formatted_list_of_xpaths, xmpp, biboumi):