salt/tests/unit/transport/test_ipc.py

157 lines
4.4 KiB
Python
Raw Normal View History

IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: Mike Place <mp@saltstack.com>
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
import os
import errno
import socket
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
import logging
import tornado.gen
import tornado.ioloop
import tornado.testing
import salt.config
import salt.exceptions
import salt.transport.ipc
import salt.transport.server
import salt.transport.client
import salt.utils.platform
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
from salt.ext import six
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
from salt.ext.six.moves import range
# Import Salt Testing libs
from tests.support.mock import MagicMock
2017-03-28 16:06:57 +00:00
from tests.support.paths import TMP
from tests.support.unit import skipIf
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
log = logging.getLogger(__name__)
@skipIf(salt.utils.platform.is_windows(), 'Windows does not support Posix IPC')
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
class BaseIPCReqCase(tornado.testing.AsyncTestCase):
'''
Test the req server/client pair
'''
def setUp(self):
super(BaseIPCReqCase, self).setUp()
#self._start_handlers = dict(self.io_loop._handlers)
2017-03-28 16:06:57 +00:00
self.socket_path = os.path.join(TMP, 'ipc_test.ipc')
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
self.server_channel = salt.transport.ipc.IPCMessageServer(
self.socket_path,
io_loop=self.io_loop,
payload_handler=self._handle_payload,
)
self.server_channel.start()
self.payloads = []
def tearDown(self):
super(BaseIPCReqCase, self).tearDown()
#failures = []
try:
self.server_channel.close()
except socket.error as exc:
if exc.errno != errno.EBADF:
# If its not a bad file descriptor error, raise
raise
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
os.unlink(self.socket_path)
#for k, v in six.iteritems(self.io_loop._handlers):
# if self._start_handlers.get(k) != v:
# failures.append((k, v))
#if len(failures) > 0:
# raise Exception('FDs still attached to the IOLoop: {0}'.format(failures))
2017-03-28 16:06:57 +00:00
del self.payloads
del self.socket_path
2017-03-28 16:06:57 +00:00
del self.server_channel
#del self._start_handlers
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
@tornado.gen.coroutine
def _handle_payload(self, payload, reply_func):
self.payloads.append(payload)
yield reply_func(payload)
if isinstance(payload, dict) and payload.get('stop'):
self.stop()
class IPCMessageClient(BaseIPCReqCase):
'''
Test all of the clear msg stuff
'''
def _get_channel(self):
channel = salt.transport.ipc.IPCMessageClient(
socket_path=self.socket_path,
io_loop=self.io_loop,
)
channel.connect(callback=self.stop)
self.wait()
return channel
def setUp(self):
super(IPCMessageClient, self).setUp()
self.channel = self._get_channel()
def tearDown(self):
super(IPCMessageClient, self).tearDown()
try:
self.channel.close()
except socket.error as exc:
if exc.errno != errno.EBADF:
# If its not a bad file descriptor error, raise
raise
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
def test_basic_send(self):
msg = {'foo': 'bar', 'stop': True}
self.channel.send(msg)
self.wait()
self.assertEqual(self.payloads[0], msg)
def test_many_send(self):
msgs = []
self.server_channel.stream_handler = MagicMock()
for i in range(0, 1000):
msgs.append('test_many_send_{0}'.format(i))
for i in msgs:
self.channel.send(i)
self.channel.send({'stop': True})
self.wait()
self.assertEqual(self.payloads[:-1], msgs)
def test_very_big_message(self):
long_str = ''.join([six.text_type(num) for num in range(10**5)])
IPC transport skeleton Basic IPC server works! Lint Skeleton of client IPC bind test Make stand-alone Adding factories for push and pull channels Allowing opts passing for consistency Tests now (mostly) work Lint Method documentation General cleanup. Migrate to inheritence. Log cleanup Migrate framing to stand-along module Migrate ipc.py to new framer Working except for serialization bug Debugging Debugging It works!! Remove ZeroMQ from TCP transport :] General cleanup Linting General cleanup Align socket name with what client expects Remove unused buffer size flag exception handling for stream close Calls to parent class inits Docs Remove debugging Remove unused function Remove unnecessary pre/post fork on msgclient Remove unecessary timeout flag Better stream/socket shutdown in server Remove unused handler Removing more unused More function cleanup Removing more unneeded cruft Lint Round out documentation More docs Misc hacks to fix up @cachedout's IPC This was using a mix of blocking and non-blocking calls, which was making a bit of a mess. connect and write are both non-blocking calls on IOStreams, so we either need to handle all the callbacks or do them in the coroutine fashion (much easier to manage). This meant that in the tests your "write" wouldn't make it out since we didn't wait on the connect. IMO we should refactor this IPC stuff to have proper async interfaces and wrap if absolutely necessary, but I think its reasonable to ask that as part of this we make some more of the core coroutines :) for #23236 Lint Remove init of io_loop because we require start() Various fixes Remove uneeded functionality Remove dup Cleanup and remove unused functions Moving toward coroutines More lint handle_connection changed to spawn Singletons for ipcclient Lint disable Remove redundent check in close() Remove duplicates in init Improved exception handling Test framework Require sock path to be passed in Better testing approach Remove unecessary __init__ Misc cleanup of unecessary methods Major rework of the IPC channels to make them work :) Remove TODO, since the feature was implemented Add more tests for IPC Add support for reconnecting clients, as well as a return from the IPCServer misc cleanup Lint test case Lint transport
2015-04-23 02:10:33 +00:00
msg = {'long_str': long_str, 'stop': True}
self.channel.send(msg)
self.wait()
self.assertEqual(msg, self.payloads[0])
def test_multistream_sends(self):
local_channel = self._get_channel()
for c in (self.channel, local_channel):
c.send('foo')
self.channel.send({'stop': True})
self.wait()
self.assertEqual(self.payloads[:-1], ['foo', 'foo'])
def test_multistream_errors(self):
local_channel = self._get_channel()
for c in (self.channel, local_channel):
c.send(None)
for c in (self.channel, local_channel):
c.send('foo')
self.channel.send({'stop': True})
self.wait()
self.assertEqual(self.payloads[:-1], [None, None, 'foo', 'foo'])