forked from luckysusanto/SisDisExperiment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_paxos.py
48 lines (36 loc) · 1.1 KB
/
test_paxos.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
45
46
47
48
import unittest
import time
from unittest import TestCase
from network import Network
from paxos import PaxosNode
class PaxosTest(TestCase):
def setUp(self):
self.nodes = []
def tearDown(self):
for node in self.nodes:
node.socket.close()
def test_leader_protocol(self):
node_ids = [1, 2, 3]
node_addresses = [
('127.0.0.1', 5001), ('127.0.0.1', 5002),
('127.0.0.1', 5003)
]
network = Network(node_ids, node_addresses)
node1 = PaxosNode(network, 1, ('127.0.0.1', 5001))
node2 = PaxosNode(network, 2, ('127.0.0.1', 5002))
node3 = PaxosNode(network, 3, ('127.0.0.1', 5003))
node1.start_listening()
node2.start_listening()
node3.start_listening()
node1.leader_protocol_thread.start()
node2.leader_protocol_thread.start()
node3.leader_protocol_thread.start()
time.sleep(0.1)
self.assertEqual(node1.is_leader, True)
self.assertEqual(node2.is_leader, False)
self.assertEqual(node3.is_leader, False)
self.assertEqual(node1.leader_id, 1)
self.assertEqual(node2.leader_id, 1)
self.assertEqual(node3.leader_id, 1)
self.nodes.extend([node1, node2, node3])
unittest.main()