2017-09-18 10:07:21 +00:00
|
|
|
import testlib
|
2018-05-28 01:34:12 +00:00
|
|
|
|
|
|
|
import mitogen.core
|
|
|
|
import mitogen.parent
|
|
|
|
|
|
|
|
|
|
|
|
@mitogen.core.takes_econtext
|
|
|
|
def allocate_an_id(econtext):
|
|
|
|
mitogen.parent.upgrade_router(econtext)
|
|
|
|
return econtext.router.allocate_id()
|
2017-09-18 10:07:21 +00:00
|
|
|
|
|
|
|
|
2017-10-01 10:00:43 +00:00
|
|
|
class SlaveTest(testlib.RouterMixin, testlib.TestCase):
|
2017-09-18 10:07:21 +00:00
|
|
|
def test_slave_allocates_id(self):
|
|
|
|
context = self.router.local()
|
2018-03-21 21:54:24 +00:00
|
|
|
# Master's allocator named the context 1.
|
|
|
|
self.assertEquals(1, context.context_id)
|
|
|
|
|
|
|
|
# First call from slave allocates a block (2..1001)
|
2018-05-28 01:34:12 +00:00
|
|
|
id_ = context.call(allocate_an_id)
|
2018-03-21 21:54:24 +00:00
|
|
|
self.assertEqual(id_, 2)
|
|
|
|
|
|
|
|
# Second call from slave allocates from block (3..1001)
|
2018-05-28 01:34:12 +00:00
|
|
|
id_ = context.call(allocate_an_id)
|
2018-03-21 21:54:24 +00:00
|
|
|
self.assertEqual(id_, 3)
|
|
|
|
|
|
|
|
# Subsequent master allocation does not collide
|
|
|
|
c2 = self.router.local()
|
|
|
|
self.assertEquals(1002, c2.context_id)
|