tests: start to fix e2e tests

python and slixmpp have moved a bit in 10 years.
This commit is contained in:
mathieui
2025-04-19 23:00:27 +02:00
parent 25de4c6b76
commit 2f59303cf9
2 changed files with 15 additions and 26 deletions
+14 -25
View File
@@ -17,8 +17,6 @@ import os
from slixmpp.xmlstream.matcher.base import MatcherBase
if not hasattr(asyncio, "ensure_future"):
asyncio.ensure_future = getattr(asyncio, "async")
class MatchAll(MatcherBase):
"""match everything"""
@@ -77,9 +75,6 @@ class XMPPComponent(slixmpp.BaseXMPP):
self.register_handler(slixmpp.Callback('Match All',
MatchAll(None),
self.handle_incoming_stanza))
self.add_event_handler("session_end", self.on_end_session)
asyncio.ensure_future(self.accept_routine())
self.scenario = scenario
@@ -105,9 +100,6 @@ class XMPPComponent(slixmpp.BaseXMPP):
self.error(error_msg)
self.run_scenario()
def on_end_session(self, _):
self.loop.stop()
def handle_incoming_stanza(self, stanza):
if self.stanza_checker:
try:
@@ -136,7 +128,6 @@ class XMPPComponent(slixmpp.BaseXMPP):
if self.biboumi:
self.biboumi.stop()
async def accept_routine(self):
self.accepting_server = await self.loop.create_server(lambda: self,
"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",
"--errors-for-leak-kinds=all", "--error-exitcode=16",
"./biboumi", "test.conf", stdin=None, stdout=self.fd,
stderr=self.fd, loop=None, limit=None)
stderr=self.fd, limit=None)
else:
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):
@@ -204,12 +195,12 @@ class BiboumiTest:
self.scenario = scenario
self.expected_code = expected_code
def run(self):
async def run(self):
with_valgrind = os.environ.get("E2E_WITH_VALGRIND") is not None
print("Running scenario: %s%s… " % (self.scenario.name, " (with valgrind)" if with_valgrind else ''), end='')
sys.stdout.flush()
# 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"):
pass
logging.basicConfig(level=logging.DEBUG,
@@ -229,12 +220,10 @@ class BiboumiTest:
# Start the XMPP component and biboumi
biboumi = BiboumiRunner(self.scenario.name)
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.process()
code = asyncio.get_event_loop().run_until_complete(biboumi.wait())
xmpp.run_scenario()
code = await biboumi.wait()
xmpp.biboumi = None
self.scenario.steps.clear()
@@ -316,18 +305,16 @@ def get_scenarios(test_path, provided_scenar_names):
return scenarios
if __name__ == '__main__':
atexit.register(asyncio.get_event_loop().close)
async def main():
provided_scenar_names = sys.argv[1:]
scenarios = get_scenarios(os.path.abspath(os.path.dirname(__file__)), provided_scenar_names)
irc_output = open("irc_output.txt", "w")
irc = IrcServerRunner()
print("Starting irc server…")
asyncio.get_event_loop().run_until_complete(irc.start())
await irc.start()
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())
if not res:
print("IRC server failed to start, see irc_output.txt for more details. Exiting…")
@@ -342,7 +329,7 @@ if __name__ == '__main__':
failures = 0
for s in scenarios:
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." %
(s.name, s.name))
failures += 1
@@ -350,7 +337,7 @@ if __name__ == '__main__':
print("Waiting for irc server to exit…")
irc.stop()
asyncio.get_event_loop().run_until_complete(irc.wait())
await irc.wait()
if failures:
print("%d test%s failed, please fix %s." % (failures, 's' if failures > 1 else '',
@@ -359,3 +346,5 @@ if __name__ == '__main__':
else:
print("All tests passed successfully")
if __name__ == '__main__':
asyncio.run(main())
+1 -1
View File
@@ -73,7 +73,7 @@ def check_xpath(xpaths, xmpp, after, stanza):
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))
if after:
if isinstance(after, collections.Iterable):
if isinstance(after, collections.abc.Iterable):
for af in after:
af(stanza, xmpp)
else: