def test_start_up_binds_first_of_real_endpoint_options(self):
service = RegionService(sentinel.advertiser)
# endpoint_1.listen(...) will bind to a random high-numbered port.
endpoint_1 = TCP4ServerEndpoint(reactor, 0)
# endpoint_2.listen(...), if attempted, will crash because only root
# (or a user with explicit capabilities) can do stuff like that. It's
# a reasonable assumption that the user running these tests is not
# root, but we'll check the port number later too to be sure.
endpoint_2 = TCP4ServerEndpoint(reactor, 1)
service.endpoints = [[endpoint_1, endpoint_2]]
yield service.startService()
self.addCleanup(wait_for_reactor(service.stopService))
# A single port has been bound.
self.assertThat(service.ports, MatchesAll(
HasLength(1), AllMatch(IsInstance(tcp.Port))))
# The port is not listening on port 1; i.e. a belt-n-braces check that
# endpoint_2 was not used.
[port] = service.ports
self.assertThat(port.getHost().port, Not(Equals(1)))
评论列表
文章目录