tests: start to fix e2e tests
python and slixmpp have moved a bit in 10 years.
This commit is contained in:
@@ -17,8 +17,6 @@ import os
|
|||||||
|
|
||||||
from slixmpp.xmlstream.matcher.base import MatcherBase
|
from slixmpp.xmlstream.matcher.base import MatcherBase
|
||||||
|
|
||||||
if not hasattr(asyncio, "ensure_future"):
|
|
||||||
asyncio.ensure_future = getattr(asyncio, "async")
|
|
||||||
|
|
||||||
class MatchAll(MatcherBase):
|
class MatchAll(MatcherBase):
|
||||||
"""match everything"""
|
"""match everything"""
|
||||||
@@ -77,9 +75,6 @@ class XMPPComponent(slixmpp.BaseXMPP):
|
|||||||
self.register_handler(slixmpp.Callback('Match All',
|
self.register_handler(slixmpp.Callback('Match All',
|
||||||
MatchAll(None),
|
MatchAll(None),
|
||||||
self.handle_incoming_stanza))
|
self.handle_incoming_stanza))
|
||||||
|
|
||||||
self.add_event_handler("session_end", self.on_end_session)
|
|
||||||
|
|
||||||
asyncio.ensure_future(self.accept_routine())
|
asyncio.ensure_future(self.accept_routine())
|
||||||
|
|
||||||
self.scenario = scenario
|
self.scenario = scenario
|
||||||
@@ -105,9 +100,6 @@ class XMPPComponent(slixmpp.BaseXMPP):
|
|||||||
self.error(error_msg)
|
self.error(error_msg)
|
||||||
self.run_scenario()
|
self.run_scenario()
|
||||||
|
|
||||||
def on_end_session(self, _):
|
|
||||||
self.loop.stop()
|
|
||||||
|
|
||||||
def handle_incoming_stanza(self, stanza):
|
def handle_incoming_stanza(self, stanza):
|
||||||
if self.stanza_checker:
|
if self.stanza_checker:
|
||||||
try:
|
try:
|
||||||
@@ -136,7 +128,6 @@ class XMPPComponent(slixmpp.BaseXMPP):
|
|||||||
if self.biboumi:
|
if self.biboumi:
|
||||||
self.biboumi.stop()
|
self.biboumi.stop()
|
||||||
|
|
||||||
|
|
||||||
async def accept_routine(self):
|
async def accept_routine(self):
|
||||||
self.accepting_server = await self.loop.create_server(lambda: self,
|
self.accepting_server = await self.loop.create_server(lambda: self,
|
||||||
"127.0.0.1", 8811, reuse_address=True)
|
"127.0.0.1", 8811, reuse_address=True)
|
||||||
@@ -175,10 +166,10 @@ class BiboumiRunner(ProcessRunner):
|
|||||||
self.create = asyncio.create_subprocess_exec("valgrind", "--suppressions=" + (os.environ.get("E2E_BIBOUMI_SUPP_DIR") or "") + "biboumi.supp", "--leak-check=full", "--show-leak-kinds=all",
|
self.create = asyncio.create_subprocess_exec("valgrind", "--suppressions=" + (os.environ.get("E2E_BIBOUMI_SUPP_DIR") or "") + "biboumi.supp", "--leak-check=full", "--show-leak-kinds=all",
|
||||||
"--errors-for-leak-kinds=all", "--error-exitcode=16",
|
"--errors-for-leak-kinds=all", "--error-exitcode=16",
|
||||||
"./biboumi", "test.conf", stdin=None, stdout=self.fd,
|
"./biboumi", "test.conf", stdin=None, stdout=self.fd,
|
||||||
stderr=self.fd, loop=None, limit=None)
|
stderr=self.fd, limit=None)
|
||||||
else:
|
else:
|
||||||
self.create = asyncio.create_subprocess_exec("./biboumi", "test.conf", stdin=None, stdout=self.fd,
|
self.create = asyncio.create_subprocess_exec("./biboumi", "test.conf", stdin=None, stdout=self.fd,
|
||||||
stderr=self.fd, loop=None, limit=None)
|
stderr=self.fd, limit=None)
|
||||||
|
|
||||||
|
|
||||||
class IrcServerRunner(ProcessRunner):
|
class IrcServerRunner(ProcessRunner):
|
||||||
@@ -204,12 +195,12 @@ class BiboumiTest:
|
|||||||
self.scenario = scenario
|
self.scenario = scenario
|
||||||
self.expected_code = expected_code
|
self.expected_code = expected_code
|
||||||
|
|
||||||
def run(self):
|
async def run(self):
|
||||||
with_valgrind = os.environ.get("E2E_WITH_VALGRIND") is not None
|
with_valgrind = os.environ.get("E2E_WITH_VALGRIND") is not None
|
||||||
print("Running scenario: [33;1m%s[0m%s… " % (self.scenario.name, " (with valgrind)" if with_valgrind else ''), end='')
|
print("Running scenario: [33;1m%s[0m%s… " % (self.scenario.name, " (with valgrind)" if with_valgrind else ''), end='')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
# Redirect the slixmpp logging into a specific file
|
# Redirect the slixmpp logging into a specific file
|
||||||
output_filename = "slixmpp_%s_output.txt" % (self.scenario.name,)
|
output_filename = f"slixmpp_{self.scenario.name}_output.txt"
|
||||||
with open(output_filename, "w"):
|
with open(output_filename, "w"):
|
||||||
pass
|
pass
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
@@ -229,12 +220,10 @@ class BiboumiTest:
|
|||||||
# Start the XMPP component and biboumi
|
# Start the XMPP component and biboumi
|
||||||
biboumi = BiboumiRunner(self.scenario.name)
|
biboumi = BiboumiRunner(self.scenario.name)
|
||||||
xmpp = XMPPComponent(self.scenario, biboumi)
|
xmpp = XMPPComponent(self.scenario, biboumi)
|
||||||
asyncio.get_event_loop().run_until_complete(biboumi.start())
|
await biboumi.start()
|
||||||
|
|
||||||
asyncio.get_event_loop().call_soon(xmpp.run_scenario)
|
xmpp.run_scenario()
|
||||||
|
code = await biboumi.wait()
|
||||||
xmpp.process()
|
|
||||||
code = asyncio.get_event_loop().run_until_complete(biboumi.wait())
|
|
||||||
xmpp.biboumi = None
|
xmpp.biboumi = None
|
||||||
self.scenario.steps.clear()
|
self.scenario.steps.clear()
|
||||||
|
|
||||||
@@ -316,18 +305,16 @@ def get_scenarios(test_path, provided_scenar_names):
|
|||||||
return scenarios
|
return scenarios
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
async def main():
|
||||||
atexit.register(asyncio.get_event_loop().close)
|
|
||||||
|
|
||||||
provided_scenar_names = sys.argv[1:]
|
provided_scenar_names = sys.argv[1:]
|
||||||
scenarios = get_scenarios(os.path.abspath(os.path.dirname(__file__)), provided_scenar_names)
|
scenarios = get_scenarios(os.path.abspath(os.path.dirname(__file__)), provided_scenar_names)
|
||||||
|
|
||||||
irc_output = open("irc_output.txt", "w")
|
irc_output = open("irc_output.txt", "w")
|
||||||
irc = IrcServerRunner()
|
irc = IrcServerRunner()
|
||||||
print("Starting irc server…")
|
print("Starting irc server…")
|
||||||
asyncio.get_event_loop().run_until_complete(irc.start())
|
await irc.start()
|
||||||
while True:
|
while True:
|
||||||
res = asyncio.get_event_loop().run_until_complete(irc.process.stderr.readline())
|
res = await irc.process.stderr.readline()
|
||||||
irc_output.write(res.decode())
|
irc_output.write(res.decode())
|
||||||
if not res:
|
if not res:
|
||||||
print("IRC server failed to start, see irc_output.txt for more details. Exiting…")
|
print("IRC server failed to start, see irc_output.txt for more details. Exiting…")
|
||||||
@@ -342,7 +329,7 @@ if __name__ == '__main__':
|
|||||||
failures = 0
|
failures = 0
|
||||||
for s in scenarios:
|
for s in scenarios:
|
||||||
test = BiboumiTest(s)
|
test = BiboumiTest(s)
|
||||||
if not test.run():
|
if not await test.run():
|
||||||
print("You can check the files slixmpp_%s_output.txt and biboumi_%s_output.txt to help you debug." %
|
print("You can check the files slixmpp_%s_output.txt and biboumi_%s_output.txt to help you debug." %
|
||||||
(s.name, s.name))
|
(s.name, s.name))
|
||||||
failures += 1
|
failures += 1
|
||||||
@@ -350,7 +337,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
print("Waiting for irc server to exit…")
|
print("Waiting for irc server to exit…")
|
||||||
irc.stop()
|
irc.stop()
|
||||||
asyncio.get_event_loop().run_until_complete(irc.wait())
|
await irc.wait()
|
||||||
|
|
||||||
if failures:
|
if failures:
|
||||||
print("%d test%s failed, please fix %s." % (failures, 's' if failures > 1 else '',
|
print("%d test%s failed, please fix %s." % (failures, 's' if failures > 1 else '',
|
||||||
@@ -359,3 +346,5 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
print("All tests passed successfully")
|
print("All tests passed successfully")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
asyncio.run(main())
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ def check_xpath(xpaths, xmpp, after, stanza):
|
|||||||
if (expected and not matched) or (not expected and matched):
|
if (expected and not matched) or (not expected and matched):
|
||||||
raise StanzaError("Received stanza\n%s\ndid not match expected xpath\n%s" % (stanza, real_xpath))
|
raise StanzaError("Received stanza\n%s\ndid not match expected xpath\n%s" % (stanza, real_xpath))
|
||||||
if after:
|
if after:
|
||||||
if isinstance(after, collections.Iterable):
|
if isinstance(after, collections.abc.Iterable):
|
||||||
for af in after:
|
for af in after:
|
||||||
af(stanza, xmpp)
|
af(stanza, xmpp)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user