Skip to content

Commit

Permalink
update tests to support gamma arg + add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
cortze committed Aug 25, 2023
1 parent 77335ef commit 97e5119
Showing 1 changed file with 76 additions and 23 deletions.
99 changes: 76 additions & 23 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ def test_network(self):
# configuration of the DHTnetwork
k = 20
size = 200
id = 0
netid = 0
fasterrorrate = 0 # apply an error rate of 0 (to check if the logic pases)
slowerrorrate = 0
conndelayrange = None
fastdelayrange = None # ms
slowdelayrange = None
overhead = 0
network, _ = generate_network(
k,
size,
id,
netid,
fasterrorrate,
slowerrorrate,
conndelayrange,
fastdelayrange,
slowdelayrange)
slowdelayrange,
overhead)

# check total size of the network
totalnodes = network.nodestore.len()
Expand Down Expand Up @@ -151,20 +153,23 @@ def test_network_initialization(self):
""" test that the routing tables for each nodeID are correctly initialized """
k = 2
size = 200
netid=0
fasterrorrate = 0 # apply an error rate of 0 (to check if the logic pases)
slowerrorrate = 0
conndalayrange = None
conndelayrange = None
fastdelayrange = None # ms
slowdelayrange = None
overhead = 0
network, nodes = generate_network(
k,
size,
id,
netid,
fasterrorrate,
slowerrorrate,
conndalayrange,
conndelayrange,
fastdelayrange,
slowdelayrange)
slowdelayrange,
overhead)

for node in nodes:
summary = node.bootstrap()
Expand All @@ -178,21 +183,23 @@ def test_dht_interop(self):
""" test if the nodes in the network actually route to the closest peer, and implicidly, if the DHTclient interface works """
k = 10
size = 500
id = 0
netid = 0
fasterrorrate = 0 # apply an error rate of 0 (to check if the logic pases)
slowerrorrate = 0
conndelayrange = None
fastdelayrange = None # ms
slowdelayrange = None
overhead = 0
_, nodes = generate_network(
k,
size,
id,
netid,
fasterrorrate,
slowerrorrate,
conndelayrange,
fastdelayrange,
slowdelayrange)
slowdelayrange,
overhead)

for node in nodes:
node.bootstrap()
Expand Down Expand Up @@ -266,13 +273,15 @@ def test_dht_interop_with_error_rate(self):
conndelayrange = [30, 30] # ms
fastdelayrange = [30, 30] # ms
slowdelayrange = None
overhead = 0
n = DHTNetwork(
netid,
fasterrorrate,
slowerrorrate,
conndelayrange,
fastdelayrange,
slowdelayrange)
slowdelayrange,
overhead)
n.init_with_random_peers(1, size, k, 3, k, 3)

randomsegment = "this is a simple segment of code"
Expand Down Expand Up @@ -327,21 +336,23 @@ def test_dht_error_rate_on_connection(self):
""" test if the nodes in the network actually route to the closest peer, and implicidly, if the DHTclient interface works """
k = 1
size = 2
id = 0
netid = 0
fasterrorrate = 20 # apply an error rate of 0 (to check if the logic pases)
slowerrorrate = 0
conndelayrange = None
fastdelayrange = None # ms
slowdelayrange = None
overhead = 0
network, nodes = generate_network(
k,
size,
id,
netid,
fasterrorrate,
slowerrorrate,
conndelayrange,
fastdelayrange,
slowdelayrange)
slowdelayrange,
overhead)
for node in nodes:
node.bootstrap()

Expand All @@ -365,21 +376,23 @@ def test_dht_provide_and_lookup(self):
""" test if the nodes in the network actually route to the closest peer, and implicidly, if the DHTclient interface works """
k = 10
size = 500
id = 0
netid = 0
fasterrorrate = 0 # apply an error rate of 0 (to check if the logic pases)
slowerrorrate = 0
conndelayrange = None
fastdelayrange = None # ms
slowdelayrange = None
overhead = 0
_, nodes = generate_network(
k,
size,
id,
netid,
fasterrorrate,
slowerrorrate,
conndelayrange,
fastdelayrange,
slowdelayrange)
slowdelayrange,
overhead)
for node in nodes:
node.bootstrap()

Expand All @@ -403,24 +416,25 @@ def test_aggregated_delays(self):
""" test if the interaction between the nodes in the network actually generate a compounded delay """
k = 10
size = 500
id = 0
netid = 0
fasterrorrate = 0 # apply an error rate of 0 (to check if the logic pases)
slowerrorrate = 0
maxDelay = 101
minDelay = 10
delayrange = range(minDelay, maxDelay, 10) # ms
fasterrordelayrange = None
slowerrordelayrange = None

overhead = 0
_, nodes = generate_network(
k,
size,
id,
netid,
fasterrorrate,
slowerrorrate,
delayrange,
fasterrordelayrange,
slowerrordelayrange)
slowerrordelayrange,
overhead)
for node in nodes:
node.bootstrap()

Expand Down Expand Up @@ -454,6 +468,44 @@ def test_aggregated_delays(self):
self.assertGreater(aggrdelay, bestdelay)
self.assertLess(aggrdelay, worstdelay)

def test_gamma_overhead(self):
""" test if the interaction between the nodes in the network actually generate a compounded delay """
netid = 0
jobs = 2
size = 500
k = 10
a = 1
b = k
stepstop = 3
overhead = 1
network = DHTNetwork(
networkid=netid,
gammaoverhead=overhead,
)

network.init_with_random_peers(jobs, size, k, a, b, stepstop)

randomSegment = "this is a simple segment of code"
segH = Hash(randomSegment)
# use random node as lookup point
publishernodeid = random.sample(range(1, size), 1)[0]
pnode = network.nodestore.get_node(publishernodeid)
self.assertNotEqual(pnode.network.len(), 0)

providesummary, aggrdelay = pnode.provide_block_segment(randomSegment)
self.assertEqual(len(providesummary["closestNodes"]), k)

interestednodeid = random.sample(range(1, size), 1)[0]
inode = network.nodestore.get_node(interestednodeid)
closestnodes, val, summary, aggrdelay = inode.lookup_for_hash(key=segH)
self.assertEqual(randomSegment, val)

supossed_overhead = 0
for i in range(summary['successfulCons']+1):
supossed_overhead += i*overhead
self.assertEqual(aggrdelay, supossed_overhead)


def test_aggregated_delays_and_alpha(self):
""" test if the interaction between the nodes in the network actually generate a compounded delay """
size = 1000
Expand Down Expand Up @@ -493,14 +545,15 @@ def test_aggregated_delays_and_alpha(self):
self.assertEqual(aggrdelay, rounds * (delay*2))


def generate_network(k, size, netid, fasterrorrate, slowerrorrate, conndalayrange, fasterrordelayrange, slowerrordelayrange):
def generate_network(k, size, netid, fasterrorrate, slowerrorrate, conndalayrange, fasterrordelayrange, slowerrordelayrange, overhead):
network = DHTNetwork(
netid,
fasterrorrate,
slowerrorrate,
conndalayrange,
fasterrordelayrange,
slowerrordelayrange)
slowerrordelayrange,
overhead)
nodeids = range(0, size, 1)
nodes = []
for i in nodeids:
Expand Down

0 comments on commit 97e5119

Please sign in to comment.