Move most of the code testing UDP from core tests to test_network #2169
|
@ -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()
|
||||||
|
|
|
@ -19,6 +19,7 @@ class TestNetwork(TestPartialRun):
|
||||||
cls.state.maximumNumberOfHalfOpenConnections = 4
|
cls.state.maximumNumberOfHalfOpenConnections = 4
|
||||||
|
|
||||||
cls.config.set('bitmessagesettings', 'sendoutgoingconnections', 'True')
|
cls.config.set('bitmessagesettings', 'sendoutgoingconnections', 'True')
|
||||||
|
cls.config.set('bitmessagesettings', 'udp', 'True')
|
||||||
|
|
||||||
# config variable is still used inside of the network ):
|
# config variable is still used inside of the network ):
|
||||||
import network
|
import network
|
||||||
|
@ -34,18 +35,14 @@ class TestNetwork(TestPartialRun):
|
||||||
def test_threads(self):
|
def test_threads(self):
|
||||||
"""Ensure all the network threads started"""
|
"""Ensure all the network threads started"""
|
||||||
threads = {
|
threads = {
|
||||||
"AddrBroadcaster", "Asyncore", "Downloader", "InvBroadcaster",
|
"AddrBroadcaster", "Announcer", "Asyncore", "Downloader",
|
||||||
"Uploader"}
|
"InvBroadcaster", "Uploader"}
|
||||||
extra = (
|
extra = self.config.getint('threads', 'receive')
|
||||||
self.config.getint('threads', 'receive')
|
|
||||||
+ self.config.safeGetBoolean('bitmessagesettings', 'udp'))
|
|
||||||
for thread in threading.enumerate():
|
for thread in threading.enumerate():
|
||||||
try:
|
try:
|
||||||
threads.remove(thread.name)
|
threads.remove(thread.name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
extra -= (
|
extra -= thread.name.startswith("ReceiveQueue_")
|
||||||
thread.name == "Announcer"
|
|
||||||
or thread.name.startswith("ReceiveQueue_"))
|
|
||||||
|
|
||||||
self.assertEqual(len(threads), 0)
|
self.assertEqual(len(threads), 0)
|
||||||
self.assertEqual(extra, 0)
|
self.assertEqual(extra, 0)
|
||||||
|
@ -66,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