Commit 9a514c89 authored by Ron Rothman's avatar Ron Rothman Committed by Jason Madden

added tests for new Pool.add parameters, blocking and timeout

parent 12893eec
...@@ -3,6 +3,7 @@ import gevent ...@@ -3,6 +3,7 @@ import gevent
from gevent import pool from gevent import pool
from gevent.event import Event from gevent.event import Event
from gevent.queue import Queue from gevent.queue import Queue
from gevent.timeout import Timeout
import greentest import greentest
import random import random
from greentest import ExpectedException from greentest import ExpectedException
...@@ -204,6 +205,46 @@ class PoolBasicTests(greentest.TestCase): ...@@ -204,6 +205,46 @@ class PoolBasicTests(greentest.TestCase):
finally: finally:
first.kill() first.kill()
def test_add_method_non_blocking(self):
p = self.klass(size=1)
first = gevent.spawn(gevent.sleep, 1000)
try:
second = gevent.spawn(gevent.sleep, 1000)
try:
p.add(first)
try:
p.add(second, blocking=False)
except pool.Full:
pass # expected
except Exception:
raise AssertionError('Expected pool.Full')
else:
raise AssertionError('Expected pool.Full')
finally:
second.kill()
finally:
first.kill()
def test_add_method_timeout(self):
p = self.klass(size=1)
first = gevent.spawn(gevent.sleep, 1000)
try:
second = gevent.spawn(gevent.sleep, 1000)
try:
p.add(first)
try:
p.add(second, timeout=0.100)
except Timeout:
pass # expected
except Exception:
raise AssertionError('expected Timeout')
else:
raise AssertionError('expected Timeout')
finally:
second.kill()
finally:
first.kill()
def test_apply(self): def test_apply(self):
p = self.klass() p = self.klass()
result = p.apply(lambda a: ('foo', a), (1, )) result = p.apply(lambda a: ('foo', a), (1, ))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment