Implement test_aborted_on_local_context_disconnect

pull/45/head
David Wilson 7 years ago
parent 1f607a6292
commit fa9def91f2

@ -74,7 +74,8 @@ def _unpickle_call_error(s):
class ChannelError(Error): class ChannelError(Error):
pass remote_msg = 'Channel closed by remote end.'
local_msg = 'Channel closed by local end.'
class StreamError(Error): class StreamError(Error):
@ -320,12 +321,12 @@ class Receiver(object):
IOLOG.debug('%r.get() got %r', self, msg) IOLOG.debug('%r.get() got %r', self, msg)
if msg == _DEAD: if msg == _DEAD:
raise ChannelError('Channel closed by local end.') raise ChannelError(ChannelError.local_msg)
# Must occur off the broker thread. # Must occur off the broker thread.
data = msg.unpickle() data = msg.unpickle()
if data == _DEAD and self.raise_channelerror: if data == _DEAD and self.raise_channelerror:
raise ChannelError('Channel closed by remote end.') raise ChannelError(ChannelError.remote_msg)
if isinstance(data, CallError): if isinstance(data, CallError):
raise data raise data
@ -795,6 +796,7 @@ class Waker(BasicStream):
Write a byte to the self-pipe, causing the IO multiplexer to wake up. Write a byte to the self-pipe, causing the IO multiplexer to wake up.
Nothing is written if the current thread is the IO multiplexer thread. Nothing is written if the current thread is the IO multiplexer thread.
""" """
IOLOG.debug('%r.wake() [fd=%r]', self, self.transmit_side.fd)
if threading.currentThread() != self._broker._thread and \ if threading.currentThread() != self._broker._thread and \
self.transmit_side.fd: self.transmit_side.fd:
os.write(self.transmit_side.fd, ' ') os.write(self.transmit_side.fd, ' ')

@ -61,12 +61,14 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
def test_returns_dead(self): def test_returns_dead(self):
assert mitogen.core._DEAD == self.local.call(func_returns_dead) assert mitogen.core._DEAD == self.local.call(func_returns_dead)
def test_aborted_on_context_disconnect(self): def test_aborted_on_local_context_disconnect(self):
assert 0, 'todo' stream = self.router._stream_by_id[self.local.context_id]
self.broker.stop_receive(stream)
def test_aborted_on_context_hang_deadline(self): recv = self.local.call_async(time.sleep, 120)
# related: how to treat context after a function call hangs self.broker.defer(stream.on_disconnect, self.broker)
assert 0, 'todo' exc = self.assertRaises(mitogen.core.ChannelError,
lambda: recv.get())
self.assertEquals(exc[0], mitogen.core.ChannelError.local_msg)
def test_aborted_on_local_broker_shutdown(self): def test_aborted_on_local_broker_shutdown(self):
assert 0, 'todo' assert 0, 'todo'

Loading…
Cancel
Save