Fix wrong comparison in reject_when_reached
We say we raise when backlog goes past max size, but actually we raise when backlogs tries to reach the max size. This patch fixes reject_when_reached to actually allow max size to be reached, but no more. Also adding missing unit test for reject_when_reached. Change-Id: Ide835b6e5fd15171b9bebc7ca112b84423b39fab
This commit is contained in:
parent
cc7bc7017a
commit
6a2f5a0bb3
|
@ -23,7 +23,7 @@ def reject_when_reached(max_backlog):
|
|||
"""Returns a function that will raise when backlog goes past max size."""
|
||||
|
||||
def _rejector(executor, backlog):
|
||||
if backlog + 1 >= max_backlog:
|
||||
if backlog >= max_backlog:
|
||||
raise futurist.RejectedSubmission("Current backlog %s is not"
|
||||
" allowed to go"
|
||||
" beyond %s" % (backlog,
|
||||
|
|
|
@ -18,6 +18,7 @@ import testscenarios
|
|||
from testtools import testcase
|
||||
|
||||
import futurist
|
||||
from futurist import rejection
|
||||
from futurist.tests import base
|
||||
|
||||
|
||||
|
@ -137,3 +138,31 @@ class TestExecutors(testscenarios.TestWithScenarios, base.TestCase):
|
|||
self.assertEqual(10, len(happy_completed) + len(unhappy_completed))
|
||||
self.assertEqual(5, len(unhappy_completed))
|
||||
self.assertEqual(5, len(happy_completed))
|
||||
|
||||
|
||||
_REJECTION = rejection.reject_when_reached(1)
|
||||
|
||||
|
||||
class TestRejection(testscenarios.TestWithScenarios, base.TestCase):
|
||||
scenarios = [
|
||||
('green', {'executor_cls': futurist.GreenThreadPoolExecutor,
|
||||
'executor_kwargs': {'check_and_reject': _REJECTION,
|
||||
'max_workers': 1}}),
|
||||
('thread', {'executor_cls': futurist.ThreadPoolExecutor,
|
||||
'executor_kwargs': {'check_and_reject': _REJECTION,
|
||||
'max_workers': 1}}),
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super(TestRejection, self).setUp()
|
||||
self.executor = self.executor_cls(**self.executor_kwargs)
|
||||
|
||||
def test_rejection(self):
|
||||
self.addCleanup(self.executor.shutdown)
|
||||
|
||||
# 1 worker + 1 item of backlog
|
||||
for _i in range(2):
|
||||
self.executor.submit(delayed, 0.5)
|
||||
|
||||
self.assertRaises(futurist.RejectedSubmission,
|
||||
self.executor.submit, returns_one)
|
||||
|
|
Loading…
Reference in New Issue