def test_beacon_already_running():
#
# NB this one has to run without the beacon fixture
#
# Bind a socket on a random port before attempting
# to start a beacon on that same port.
#
port = random.choice(nw0.config.DYNAMIC_PORTS)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind(("", port))
try:
assert nw0.discovery._beacon is None
nw0.discovery._start_beacon(port=port)
assert nw0.discovery._beacon is nw0.discovery._remote_beacon
finally:
s.close()
#
# Make sure any future beacon use assumes it's not
# already running.
#
nw0.discovery._stop_beacon()
评论列表
文章目录