git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/prosody: fix broken tests
commit3fd5a416769fe53a72de49161c8bea4f2b3ea194 authorAndrey Golovizin <ag@sologoc.com> dateThu 11 Feb 2021, 18:46 (6 years ago) parent9879556
2 files changed+25−3
nixos/tests/xmpp/prosody.nix+1−1 nixos/tests/xmpp/xmpp-sendmessage.nix+24−2
nixos/tests/xmpp/prosody.nix+1−1
@@ -85,7 +85,7 @@ in import ../make-test-python.nix {
8585 server.succeed('prosodyctl status | grep "Prosody is running"')
8686
8787 server.succeed("create-prosody-users")
88− client.succeed('send-message 2>&1 | grep "XMPP SCRIPT TEST SUCCESS"')
88+ client.succeed("send-message")
8989 server.succeed("delete-prosody-users")
9090 '';
9191}
nixos/tests/xmpp/xmpp-sendmessage.nix+24−2
@@ -23,8 +23,26 @@ class CthonTest(ClientXMPP):
2323 def __init__(self, jid, password):
2424 ClientXMPP.__init__(self, jid, password)
2525 self.add_event_handler("session_start", self.session_start)
26+ self.test_succeeded = False
2627
2728 async def session_start(self, event):
29+ try:
30+ # Exceptions in event handlers are printed to stderr but not
31+ # propagated, they do not make the script terminate with a non-zero
32+ # exit code. We use the `test_succeeded` flag as a workaround and
33+ # check it later at the end of the script to exit with a proper
34+ # exit code.
35+ # Additionally, this flag ensures that this event handler has been
36+ # actually run by ClientXMPP, which may well not be the case.
37+ await self.test_xmpp_server()
38+ self.test_succeeded = True
39+ finally:
40+ # Even if an exception happens in `test_xmpp_server()`, we still
41+ # need to disconnect explicitly, otherwise the process will hang
42+ # forever.
43+ self.disconnect(wait=True)
44+
45+ async def test_xmpp_server(self):
2846 log = logging.getLogger(__name__)
2947 self.send_presence()
3048 self.get_roster()
@@ -42,11 +60,12 @@ class CthonTest(ClientXMPP):
4260 log.error("ERROR: Cannot run upload command. XEP_0363 seems broken")
4361 sys.exit(1)
4462 log.info('Upload success!')
63+
4564 # Test MUC
46− self.plugin['xep_0045'].join_muc('testMucRoom', 'cthon98', wait=True)
65+ # TODO: use join_muc_wait() after slixmpp 1.8.0 is released.
66+ self.plugin['xep_0045'].join_muc('testMucRoom', 'cthon98')
4767 log.info('MUC join success!')
4868 log.info('XMPP SCRIPT TEST SUCCESS')
49− self.disconnect(wait=True)
5069
5170
5271if __name__ == '__main__':
@@ -62,4 +81,7 @@ if __name__ == '__main__':
6281 ct.register_plugin('xep_0045')
6382 ct.connect(("server", 5222))
6483 ct.process(forever=False)
84+
85+ if not ct.test_succeeded:
86+ sys.exit(1)
6587''