From 5ae33d6b9ed47bf43626066c5bdc4d91a7b75db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 12 Feb 2017 16:50:47 +0100 Subject: e2e: add tests for the linger time option --- tests/end_to_end/__main__.py | 54 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index 20730a7..92a903c 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import collections +import datetime import slixmpp import asyncio import logging @@ -95,7 +96,11 @@ class XMPPComponent(slixmpp.BaseXMPP): def run_scenario(self): if self.scenario.steps: step = self.scenario.steps.pop(0) - step(self, self.biboumi) + try: + step(self, self.biboumi) + except Exception as e: + self.error(e) + self.run_scenario() else: if self.biboumi: self.biboumi.stop() @@ -261,6 +266,16 @@ def expect_stanza(xpaths, xmpp, biboumi, optional=False, after=None): else: print("Warning, from argument type passed to expect_stanza: %s" % (type(xpaths))) +def save_datetime(xmpp, biboumi): + xmpp.saved_values["saved_datetime"] = datetime.datetime.now() + asyncio.get_event_loop().call_soon(xmpp.run_scenario) + +def expect_now_is_after(timedelta, xmpp, biboumi): + time_passed = datetime.datetime.now() - xmpp.saved_values["saved_datetime"] + if time_passed < timedelta: + raise StanzaError("Not enough time has passed: %s instead of %s" % (time_passed, timedelta)) + asyncio.get_event_loop().call_soon(xmpp.run_scenario) + # list_of_xpaths: [(xpath, xpath), (xpath, xpath), (xpath)] def expect_unordered(list_of_xpaths, xmpp, biboumi): formatted_list_of_xpaths = [] @@ -473,7 +488,6 @@ def extract_attribute(xpath, name, stanza): def save_value(name, func, stanza, xmpp): xmpp.saved_values[name] = func(stanza) - if __name__ == '__main__': atexit.register(asyncio.get_event_loop().close) @@ -1947,6 +1961,42 @@ if __name__ == '__main__': partial(send_stanza, ""), partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='canceled']"), ]), + Scenario("irc_server_linger_time", + [ + handshake_sequence(), + # Set a custom value for the linger_time option, using the ad-hoc command + partial(send_stanza, ""), + partial(expect_stanza, ("/iq[@type='result']/commands:command[@node='configure'][@sessionid][@status='executing']", + "/iq/commands:command/dataform:x[@type='form']/dataform:title[text()='Configure the IRC server irc.localhost']", + "/iq/commands:command/commands:actions/commands:next", + ), + after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid")) + ), + partial(send_stanza, "" + "" + "" + "3" + ""), + partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='completed']/commands:note[@type='info'][text()='Configuration successfully applied.']"), + + partial(send_stanza, + ""), + connection_sequence("irc.localhost", '{jid_one}/{resource_one}'), + partial(expect_stanza, + "/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"), + partial(expect_stanza, + ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']") + ), + partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), + + partial(save_datetime), + partial(send_stanza, ""), + partial(expect_stanza, "/presence[@type='unavailable'][@from='#foo%{irc_server_one}/{nick_one}']"), + partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Closing Link: localhost (Client Quit)']"), + partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Connection closed.']"), + partial(expect_now_is_after, datetime.timedelta(seconds=3)), + ]), Scenario("irc_tls_connection", [ handshake_sequence(), -- cgit v1.2.3