mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-07 10:56:49 +00:00
Add servers of happiness hypothesis testing
Fix happiness test var names Remove unused imports Get rid of trailing whitespace
This commit is contained in:
parent
ef17ef2c62
commit
e68b331bb1
22
integration/test_hypothesis_happiness.py
Normal file
22
integration/test_hypothesis_happiness.py
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from twisted.trial import unittest
|
||||
from hypothesis import given
|
||||
from hypothesis.strategies import text, sets
|
||||
from allmydata.immutable import happiness_upload
|
||||
|
||||
|
||||
class Happiness(unittest.TestCase):
|
||||
|
||||
@given(sets(elements=text(min_size=1), min_size=4, max_size=4), sets(elements=text(min_size=1), min_size=4))
|
||||
def test_hypothesis_unhappy(self, peers, shares):
|
||||
"""
|
||||
similar to test_unhappy we test that the resulting happiness is always 4 since the size of peers is 4.
|
||||
"""
|
||||
# https://hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.sets
|
||||
# hypothesis.strategies.sets(elements=None, min_size=None, average_size=None, max_size=None)[source]
|
||||
readonly_peers = set()
|
||||
peers_to_shares = {}
|
||||
places = happiness_upload.share_placement(peers, readonly_peers, shares, peers_to_shares)
|
||||
happiness = happiness_upload.calculate_happiness(places)
|
||||
self.assertEqual(4, happiness)
|
1
setup.py
1
setup.py
@ -284,6 +284,7 @@ setup(name="tahoe-lafs", # also set in __init__.py
|
||||
"txi2p >= 0.3.2", # in case pip's resolver doesn't work
|
||||
"pytest",
|
||||
"pytest-twisted",
|
||||
"hypothesis >= 3.6.1",
|
||||
],
|
||||
"tor": [
|
||||
"foolscap[tor] >= 0.12.5",
|
||||
|
@ -796,7 +796,7 @@ class IPeerSelector(Interface):
|
||||
I return whether the share assignments I'm currently using
|
||||
reflect a healthy file, based on my internal definitions.
|
||||
"""
|
||||
|
||||
|
||||
def needs_recomputation():
|
||||
"""
|
||||
I return True if the share assignments I last returned may have
|
||||
|
@ -31,25 +31,21 @@ class Happiness(unittest.TestCase):
|
||||
def test_placement_simple(self):
|
||||
|
||||
shares = {'share0', 'share1', 'share2'}
|
||||
peers = {
|
||||
'peer0',
|
||||
'peer1',
|
||||
}
|
||||
peers = {'peer0', 'peer1'}
|
||||
readonly_peers = {'peer0'}
|
||||
peers_to_shares = {
|
||||
'peer0': {'share2'},
|
||||
'peer1': [],
|
||||
}
|
||||
|
||||
places0 = happiness_upload.share_placement(peers, readonly_peers, shares, peers_to_shares)
|
||||
places = happiness_upload.share_placement(peers, readonly_peers, shares, peers_to_shares)
|
||||
|
||||
if False:
|
||||
print("places0")
|
||||
for k, v in places0.items():
|
||||
for k, v in places.items():
|
||||
print(" {} -> {}".format(k, v))
|
||||
|
||||
self.assertEqual(
|
||||
places0,
|
||||
places,
|
||||
{
|
||||
'share0': {'peer1'},
|
||||
'share1': {'peer1'},
|
||||
@ -86,7 +82,7 @@ class Happiness(unittest.TestCase):
|
||||
'peerB': set(),
|
||||
}
|
||||
|
||||
places0 = happiness_upload.share_placement(peers, readonly_peers, shares, peers_to_shares)
|
||||
places = happiness_upload.share_placement(peers, readonly_peers, shares, peers_to_shares)
|
||||
|
||||
# share N maps to peer N
|
||||
# i.e. this says that share0 should be on peer0, share1 should
|
||||
@ -95,10 +91,9 @@ class Happiness(unittest.TestCase):
|
||||
'share{}'.format(i): {'peer{}'.format(i)}
|
||||
for i in range(10)
|
||||
}
|
||||
self.assertEqual(expected, places0)
|
||||
self.assertEqual(expected, places)
|
||||
|
||||
def test_unhappy(self):
|
||||
|
||||
shares = {
|
||||
'share1', 'share2', 'share3', 'share4', 'share5',
|
||||
}
|
||||
@ -106,9 +101,7 @@ class Happiness(unittest.TestCase):
|
||||
'peer1', 'peer2', 'peer3', 'peer4',
|
||||
}
|
||||
readonly_peers = set()
|
||||
peers_to_shares = {
|
||||
}
|
||||
|
||||
peers_to_shares = {}
|
||||
places = happiness_upload.share_placement(peers, readonly_peers, shares, peers_to_shares)
|
||||
happiness = happiness_upload.calculate_happiness(places)
|
||||
self.assertEqual(4, happiness)
|
||||
|
@ -4,10 +4,7 @@ reporting it in messages
|
||||
"""
|
||||
|
||||
from copy import deepcopy
|
||||
from allmydata.immutable.happiness_upload import share_placement
|
||||
from allmydata.immutable.happiness_upload import calculate_happiness
|
||||
from allmydata.immutable.happiness_upload import residual_network
|
||||
from allmydata.immutable.happiness_upload import bfs
|
||||
from allmydata.immutable.happiness_upload import augmenting_path_for
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user