Skip to content

Commit

Permalink
sloppy
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Apr 29, 2015
1 parent 3dd7121 commit e544b4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions celery/concurrency/asynpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _get_job_writer(job):
return writer() # is a weakref


if hasattr(select, 'poll', None):
if hasattr(select, 'poll'):
def _select_imp(readers=None, writers=None, err=None, timeout=0,
poll=select.poll, POLLIN=select.POLLIN,
POLLOUT=select.POLLOUT, POLLERR=select.POLLERR):
Expand Down Expand Up @@ -146,7 +146,7 @@ def _select_imp(readers=None, writers=None, err=None, timeout=0):


def _select(readers=None, writers=None, err=None, timeout=0,
_select_imp=_select_imp):
poll=_select_imp):
"""Simple wrapper to :class:`~select.select`, using :`~select.poll`
as the implementation.
Expand All @@ -170,7 +170,7 @@ def _select(readers=None, writers=None, err=None, timeout=0,
writers = set() if writers is None else writers
err = set() if err is None else err
try:
return _select_imp(readers, writers, err, timeout)
return poll(readers, writers, err, timeout)
except (select.error, socket.error) as exc:
if exc.errno == errno.EINTR:
return set(), set(), 1
Expand Down
34 changes: 17 additions & 17 deletions celery/tests/concurrency/test_prefork.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,46 +154,46 @@ def test_select(self, __select):
ebadf.errno = errno.EBADF
with patch('select.poll', create=True) as poller:
poll = poller.return_value = Mock(name='poll.poll')
poll.poll.return_value = [(3, select.POLLIN)]
poll.return_value = {3}, set(), 0
self.assertEqual(
asynpool._select({3}, poll=poller),
asynpool._select({3}, poll=poll),
({3}, set(), 0),
)

poll.poll.return_value = [(3, select.POLLERR)]
poll.return_value = {3}, set(), 0
self.assertEqual(
asynpool._select({3}, None, {3}, poll=poller),
asynpool._select({3}, None, {3}, poll=poll),
({3}, set(), 0),
)

eintr = socket.error()
eintr.errno = errno.EINTR
poll.poll.side_effect = eintr
poll.side_effect = eintr

readers = {3}
self.assertEqual(
asynpool._select(readers, poll=poller),
asynpool._select(readers, poll=poll),
(set(), set(), 1),
)
self.assertIn(3, readers)

with patch('select.poll') as poller:
poll = poller.return_value = Mock(name='poll.poll')
poll.poll.side_effect = ebadf
poll.side_effect = ebadf
with patch('select.select') as selcheck:
selcheck.side_effect = ebadf
readers = {3}
self.assertEqual(
asynpool._select(readers, poll=poller),
asynpool._select(readers, poll=poll),
(set(), set(), 1),
)
self.assertNotIn(3, readers)

with patch('select.poll') as poller:
poll = poller.return_value = Mock(name='poll.poll')
poll.poll.side_effect = MemoryError()
poll.side_effect = MemoryError()
with self.assertRaises(MemoryError):
asynpool._select({1}, poll=poller)
asynpool._select({1}, poll=poll)

with patch('select.poll') as poller:
poll = poller.return_value = Mock(name='poll.poll')
Expand All @@ -202,9 +202,9 @@ def test_select(self, __select):
def se(*args):
selcheck.side_effect = MemoryError()
raise ebadf
poll.poll.side_effect = se
poll.side_effect = se
with self.assertRaises(MemoryError):
asynpool._select({3}, poll=poller)
asynpool._select({3}, poll=poll)

with patch('select.poll') as poller:
poll = poller.return_value = Mock(name='poll.poll')
Expand All @@ -214,17 +214,17 @@ def se2(*args):
selcheck.side_effect = socket.error()
selcheck.side_effect.errno = 1321
raise ebadf
poll.poll.side_effect = se2
poll.side_effect = se2
with self.assertRaises(socket.error):
asynpool._select({3}, poll=poller)
asynpool._select({3}, poll=poll)

with patch('select.poll') as poller:
poll = poller.return_value = Mock(name='poll.poll')

poll.poll.side_effect = socket.error()
poll.poll.side_effect.errno = 34134
poll.side_effect = socket.error()
poll.side_effect.errno = 34134
with self.assertRaises(socket.error):
asynpool._select({3}, poll=poller)
asynpool._select({3}, poll=poll)

def test_promise(self):
fun = Mock()
Expand Down

0 comments on commit e544b4e

Please sign in to comment.