diff options
author | Ninjatrappeur <NinjaTrappeur@users.noreply.github.com> | 2021-02-13 15:22:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-13 15:22:48 +0100 |
commit | 2f80425e6e33cf3279ae508c71da34aea0bda9c6 (patch) | |
tree | 9616ce6de16b31d4b7d5d967bc6792603aa1c34e /nixos | |
parent | 3b77e7c9678711543b3f323316d46ea8e01c6cb0 (diff) | |
parent | 3fd5a416769fe53a72de49161c8bea4f2b3ea194 (diff) |
Merge pull request #112801 from erosennin/prosody-tests
nixos/prosody: fix broken tests
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/tests/xmpp/prosody.nix | 2 | ||||
-rw-r--r-- | nixos/tests/xmpp/xmpp-sendmessage.nix | 26 |
2 files changed, 25 insertions, 3 deletions
diff --git a/nixos/tests/xmpp/prosody.nix b/nixos/tests/xmpp/prosody.nix index e7755e24bab41..2eb06d88287f0 100644 --- a/nixos/tests/xmpp/prosody.nix +++ b/nixos/tests/xmpp/prosody.nix @@ -85,7 +85,7 @@ in import ../make-test-python.nix { server.succeed('prosodyctl status | grep "Prosody is running"') server.succeed("create-prosody-users") - client.succeed('send-message 2>&1 | grep "XMPP SCRIPT TEST SUCCESS"') + client.succeed("send-message") server.succeed("delete-prosody-users") ''; } diff --git a/nixos/tests/xmpp/xmpp-sendmessage.nix b/nixos/tests/xmpp/xmpp-sendmessage.nix index 30945e68300a8..47a77f524c6af 100644 --- a/nixos/tests/xmpp/xmpp-sendmessage.nix +++ b/nixos/tests/xmpp/xmpp-sendmessage.nix @@ -23,8 +23,26 @@ class CthonTest(ClientXMPP): def __init__(self, jid, password): ClientXMPP.__init__(self, jid, password) self.add_event_handler("session_start", self.session_start) + self.test_succeeded = False async def session_start(self, event): + try: + # Exceptions in event handlers are printed to stderr but not + # propagated, they do not make the script terminate with a non-zero + # exit code. We use the `test_succeeded` flag as a workaround and + # check it later at the end of the script to exit with a proper + # exit code. + # Additionally, this flag ensures that this event handler has been + # actually run by ClientXMPP, which may well not be the case. + await self.test_xmpp_server() + self.test_succeeded = True + finally: + # Even if an exception happens in `test_xmpp_server()`, we still + # need to disconnect explicitly, otherwise the process will hang + # forever. + self.disconnect(wait=True) + + async def test_xmpp_server(self): log = logging.getLogger(__name__) self.send_presence() self.get_roster() @@ -42,11 +60,12 @@ class CthonTest(ClientXMPP): log.error("ERROR: Cannot run upload command. XEP_0363 seems broken") sys.exit(1) log.info('Upload success!') + # Test MUC - self.plugin['xep_0045'].join_muc('testMucRoom', 'cthon98', wait=True) + # TODO: use join_muc_wait() after slixmpp 1.8.0 is released. + self.plugin['xep_0045'].join_muc('testMucRoom', 'cthon98') log.info('MUC join success!') log.info('XMPP SCRIPT TEST SUCCESS') - self.disconnect(wait=True) if __name__ == '__main__': @@ -62,4 +81,7 @@ if __name__ == '__main__': ct.register_plugin('xep_0045') ct.connect(("server", 5222)) ct.process(forever=False) + + if not ct.test_succeeded: + sys.exit(1) '' |