diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-21 12:56:13 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-21 12:57:43 +0000 |
commit | 5754ac7dd79afead22a8ddf8d4d5e67178aa5168 (patch) | |
tree | 054c6ad6f0446a74b606ecf5f95dbbfad42ba00b | |
parent | 9cf029a190b007c10e36c6c43bdb0acbd07b367e (diff) | |
download | morph-5754ac7dd79afead22a8ddf8d4d5e67178aa5168.tar.gz |
distbuild: Add test for InitiatorConnection
We can't expect that users will always have identical versions of Morph
on their local machines as on their distbuild server. So we need to test
that distbuild can handle the possibilities of version mismatches.
-rw-r--r-- | distbuild/initiator_connection_tests.py | 68 | ||||
-rw-r--r-- | without-test-modules | 1 |
2 files changed, 68 insertions, 1 deletions
diff --git a/distbuild/initiator_connection_tests.py b/distbuild/initiator_connection_tests.py new file mode 100644 index 00000000..9d5145cf --- /dev/null +++ b/distbuild/initiator_connection_tests.py @@ -0,0 +1,68 @@ +# coding=utf8 +# mainloop/initiator_connection_tests.py -- tests talking to clients +# +# Copyright (C) 2015 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.. + + +import contextlib +import json +import logging +import socket +import unittest + +import distbuild + + +class InitiatorConnectionTests(unittest.TestCase): + def setUp(self): + self.loop = distbuild.MainLoop() + + @contextlib.contextmanager + def json_initiator_connection(self, port): + '''Return a JsonMachine connected to an InitiatorConnection.''' + listener = distbuild.ListenServer( + 'localhost', port, distbuild.InitiatorConnection, [None, None]) + self.loop.add_state_machine(listener) + + listen_socket = socket.socket() + json_machine = None + try: + listen_socket.connect(('localhost', port)) + self.loop._run_once() + + json_machine = distbuild.JsonMachine(listen_socket) + self.loop.add_state_machine(json_machine) + + yield json_machine + finally: + logging.info('Shutting down test InitiatorConnection') + if json_machine: + json_machine.close() + listen_socket.shutdown(socket.SHUT_RDWR) + listener.close() + self.loop.run() + + def test_invalid_message_from_initiator(self): + '''Malformed messages from clients should not break anything.''' + + invalid_build_request_message = { + 'typeo': 'build-request', + } + + with self.json_initiator_connection(7879) as jm: + jm.send(invalid_build_request_message) + self.loop._run_once() + self.loop._run_once() diff --git a/without-test-modules b/without-test-modules index 584e603b..5ff95337 100644 --- a/without-test-modules +++ b/without-test-modules @@ -39,7 +39,6 @@ distbuild/eventsrc.py distbuild/helper_router.py distbuild/idgen.py distbuild/initiator.py -distbuild/initiator_connection.py distbuild/json_router.py distbuild/mainloop.py distbuild/protocol.py |