Fix select_test failure, remove crap old timing_test.

wip-fakessh-exit-status
David Wilson 7 years ago
parent 9c8ff7ecf6
commit 690ee6dbe2

@ -265,11 +265,15 @@ class Sender(object):
def _queue_interruptible_get(queue, timeout=None, block=True):
if timeout:
# bool is subclass of int, cannot use isinstance!
assert timeout is None or type(timeout) in (int, long, float)
assert isinstance(block, bool)
if timeout is not None:
timeout += time.time()
msg = None
while msg is None and (timeout is None or timeout < time.time()):
while msg is None and (timeout is None or timeout > time.time()):
try:
msg = queue.get(block, 0.5)
except Queue.Empty:
@ -309,11 +313,11 @@ class Receiver(object):
def empty(self):
return self._queue.empty()
def get(self, timeout=None):
IOLOG.debug('%r.on_receive(timeout=%r)', self, timeout)
def get(self, timeout=None, block=True):
IOLOG.debug('%r.get(timeout=%r, block=%r)', self, timeout, block)
msg = _queue_interruptible_get(self._queue, timeout)
IOLOG.debug('%r.on_receive() got %r', self, msg)
msg = _queue_interruptible_get(self._queue, timeout, block=block)
IOLOG.debug('%r.get() got %r', self, msg)
if msg == _DEAD:
raise ChannelError('Channel closed by local end.')

@ -321,7 +321,7 @@ class Select(object):
while True:
recv = mitogen.core._queue_interruptible_get(self._queue, timeout)
try:
msg = recv.get(False)
msg = recv.get(block=False)
if self._oneshot:
self.remove(recv)
return recv, msg

@ -1,23 +0,0 @@
#!/usr/bin/env python
import socket
import time
import unittest
import mitogen.master
import mitogen.utils
@mitogen.utils.with_router
def do_stuff(router):
context = router.connect(mitogen.master.Stream)
t0 = time.time()
ncalls = 1000
for x in xrange(ncalls):
context.call(socket.gethostname)
return (1e6 * (time.time() - t0)) / ncalls
class LocalContextTimingTest(unittest.TestCase):
def test_timing(self):
self.assertLess(do_stuff(), 1000)
Loading…
Cancel
Save