-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest_peer_socket_pool.py
44 lines (32 loc) · 1.16 KB
/
test_peer_socket_pool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import unittest
from support.peer_socket_pool_fixture import MockPeer
from groundstation.peer_socket_pool import PeerSocketPool
class TestPeerSocketPool(unittest.TestCase):
def test_add_remove(self):
pool = PeerSocketPool()
peer = MockPeer('127.0.0.1')
pool.append(peer)
pool.remove(peer)
self.assertEqual(0, len(pool))
def test_throws_error_on_remove_nonexistant_peer(self):
pool = PeerSocketPool()
peer = MockPeer('127.0.0.1')
self.assertRaises(AttributeError, pool.remove, peer)
def test_safe_multiple_removes(self):
pool = PeerSocketPool()
peer = MockPeer('127.0.0.1')
pool.append(peer)
pool.remove(peer)
self.assertEqual(0, len(pool))
pool.remove(peer)
self.assertEqual(0, len(pool))
def test_raises_after_purge(self):
pool = PeerSocketPool()
peer = MockPeer('127.0.0.1')
pool.append(peer)
pool.remove(peer)
self.assertEqual(0, len(pool))
pool.remove(peer)
self.assertEqual(0, len(pool))
pool.purge(peer.peer)
self.assertRaises(AttributeError, pool.remove, peer)