Fix select_test failure, remove crap old timing_test.

pull/45/head
David Wilson 7 years ago
parent 291a44dc34
commit eac5daf28d

@ -265,11 +265,15 @@ class Sender(object):
def _queue_interruptible_get(queue, timeout=None, block=True): 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() timeout += time.time()
msg = None 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: try:
msg = queue.get(block, 0.5) msg = queue.get(block, 0.5)
except Queue.Empty: except Queue.Empty:
@ -309,11 +313,11 @@ class Receiver(object):
def empty(self): def empty(self):
return self._queue.empty() return self._queue.empty()
def get(self, timeout=None): def get(self, timeout=None, block=True):
IOLOG.debug('%r.on_receive(timeout=%r)', self, timeout) IOLOG.debug('%r.get(timeout=%r, block=%r)', self, timeout, block)
msg = _queue_interruptible_get(self._queue, timeout) msg = _queue_interruptible_get(self._queue, timeout, block=block)
IOLOG.debug('%r.on_receive() 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('Channel closed by local end.')

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