Move most of the logic of TestCore.test_udp() into the TestNetwork
This commit is contained in:
parent
606b6d7d08
commit
c5ced60d5d
|
@ -310,26 +310,6 @@ class TestCore(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
return self.fail('No Announcer thread found')
|
return self.fail('No Announcer thread found')
|
||||||
|
|
||||||
for _ in range(20): # wait for UDP socket
|
|
||||||
for sock in BMConnectionPool().udpSockets.values():
|
|
||||||
thread.announceSelf()
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
time.sleep(1)
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
self.fail('UDP socket is not started')
|
|
||||||
|
|
||||||
for _ in range(20):
|
|
||||||
if state.discoveredPeers:
|
|
||||||
peer = state.discoveredPeers.keys()[0]
|
|
||||||
self.assertEqual(peer.port, 8444)
|
|
||||||
break
|
|
||||||
time.sleep(1)
|
|
||||||
else:
|
|
||||||
self.fail('No self in discovered peers')
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _decode_msg(data, pattern):
|
def _decode_msg(data, pattern):
|
||||||
proto = BMProto()
|
proto = BMProto()
|
||||||
|
|
|
@ -63,6 +63,31 @@ class TestNetwork(TestPartialRun):
|
||||||
else:
|
else:
|
||||||
self.fail('Have not started any connection in 30 sec')
|
self.fail('Have not started any connection in 30 sec')
|
||||||
|
|
||||||
|
def test_udp(self):
|
||||||
|
"""Invoke AnnounceThread.announceSelf() and check discovered peers"""
|
||||||
|
for _ in range(20):
|
||||||
|
if self.pool.udpSockets:
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
else:
|
||||||
|
self.fail('No UDP sockets found in 20 sec')
|
||||||
|
|
||||||
|
for _ in range(10):
|
||||||
|
try:
|
||||||
|
self.state.announceThread.announceSelf()
|
||||||
|
except AttributeError:
|
||||||
|
self.fail('state.announceThread is not set properly')
|
||||||
|
time.sleep(1)
|
||||||
|
try:
|
||||||
|
peer = self.state.discoveredPeers.popitem()[0]
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
self.assertEqual(peer.port, 8444)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.fail('No self in discovered peers')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
super(TestNetwork, cls).tearDownClass()
|
super(TestNetwork, cls).tearDownClass()
|
||||||
|
|
Reference in New Issue
Block a user