Commit 304784ba authored by zhifan huang's avatar zhifan huang

chore: correct typo error

parent 7c56771f
...@@ -3,6 +3,7 @@ import os ...@@ -3,6 +3,7 @@ import os
import sys import sys
import unittest import unittest
import time import time
import collections
from mock import patch, Mock from mock import patch, Mock
...@@ -23,11 +24,11 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -23,11 +24,11 @@ class testBaseTunnelManager(unittest.TestCase):
def setUp(self): def setUp(self):
patcher = patch("re6st.cache.Cache") patcher = patch("re6st.cache.Cache")
pacher_sock = patch("socket.socket") patcher_sock = patch("socket.socket")
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
self.addCleanup(pacher_sock.stop) self.addCleanup(patcher_sock.stop)
self.cache = patcher.start()() self.cache = patcher.start()()
self.sock = pacher_sock.start() self.sock = patcher_sock.start()
self.cache.same_country = False self.cache.same_country = False
address = [(2, [('10.0.0.2', '1194', 'udp'), ('10.0.0.2', '1194', 'tcp')])] address = [(2, [('10.0.0.2', '1194', 'udp'), ('10.0.0.2', '1194', 'tcp')])]
...@@ -190,5 +191,47 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -190,5 +191,47 @@ class testBaseTunnelManager(unittest.TestCase):
self.assertEqual(peer.version, version2) self.assertEqual(peer.version, version2)
self.assertEqual(selectTimeout.call_args[0][1], self.tunnel.newVersion) self.assertEqual(selectTimeout.call_args[0][1], self.tunnel.newVersion)
def test_invalidatePeers(self):
Peer = collections.namedtuple("Peer", ["prefix", "stop_date"])
p1 = Peer("0001", 0)
p2 = Peer("0002", time.time() + 30)
p3 = Peer("0003", time.time() + 100)
self.tunnel._peers = [p1, p2, p3]
self.tunnel.invalidatePeers()
self.assertEqual(self.tunnel._peers, [p2, p3])
self.assertIn((p2.stop_date,self.tunnel.invalidatePeers),
self.tunnel._timeouts)
@patch("re6st.tunnel.BaseTunnelManager._sendto")
def test_sendto(self, _sendto):
"""send to known peer"""
p = Mock()
p.prefix = format(3, '016b')
p.connected = True
self.tunnel._peers.append(p)
msg = "a msg"
self.tunnel.sendto(p.prefix, msg)
self.assertIn(msg, _sendto.call_args.args)
self.assertIn(p, _sendto.call_args.args)
@patch("re6st.tunnel.BaseTunnelManager._sendto")
def test_sendto_unknown(self, _sendto):
"""send to known peer"""
prefix = format(3, '016b')
self.tunnel.sendto(prefix, "a msg")
peer = self.tunnel._getPeer(prefix)
self.assertEqual(peer.prefix, prefix)
_sendto.assert_called_once()
def handlePeerEvent(self):
pass
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment