-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_network.py
44 lines (37 loc) · 1.38 KB
/
test_network.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
import sys
sys.path.append(".")
from network import NetworkMap
from node import Node
from util import Signature, Request, Config
import asyncio
import time
class MockNode(Node):
def __init__(self):
super().__init__()
self.calls = []
async def client_request(self, request, signature):
self.calls.append('client_request')
async def pre_prepare(self, view, sequence, request, signature):
self.calls.append('pre_prepare')
async def prepare(self, view, sequence, request, signature):
self.calls.append('prepare')
async def commit(self, view, sequence, request, signature):
self.calls.append('commit')
def get_pk(self):
self.calls.append('get_pk')
return 'dummy'
class TestNetworkMap(unittest.TestCase):
def test_NetworkMap_broadcast(self):
nm = NetworkMap(Config(5, 3), network_delay=100)
for i in range(5):
nm.register_lead(MockNode(), Signature('dummy'+str(i), '34', 'aaa'))
nm.broadcast('client_request',
{'request': Request('request', 123), 'signature' : Signature('12', '34', 'aaa')})
time.sleep(5)
nm.shutdown()
for key in nm.get_lead_nodes():
self.assertTrue( 'client_request' in nm.get_node(key).get_node().calls)
if __name__ == '__main__':
tnm = TestNetworkMap()
tnm.test_NetworkMap_broadcast()