Fixed f-resilient uniform strategy bug (#8).

When constructing an f-resilient uniform strategy, the read quorums were
being used for the write quorums. I added a unit test that fails because
of this bug and then fixed the bug to make the test pass.

Thanks so much @samueleresca for finding this bug!
This commit is contained in:
Michael Whittaker 2021-06-07 08:49:12 -07:00
parent d83a811a90
commit 490b7d35ea
2 changed files with 13 additions and 1 deletions

View file

@ -176,7 +176,7 @@ class QuorumSystem(Generic[T]):
else:
xs = list(self.elements())
read_quorums = list(self._f_resilient_quorums(f, xs, self.reads))
write_quorums = list(self._f_resilient_quorums(f, xs, self.reads))
write_quorums = list(self._f_resilient_quorums(f, xs, self.writes))
if len(read_quorums) == 0:
raise NoStrategyFoundError(
f'There are no {f}-resilient read quorums')

View file

@ -44,6 +44,8 @@ class TestQuorumSystem(unittest.TestCase):
b = Node('b')
c = Node('c')
d = Node('d')
e = Node('e')
f = Node('f')
sigma = QuorumSystem(reads=a).uniform_strategy()
self.assertEqual(sigma.sigma_r, {
@ -128,6 +130,16 @@ class TestQuorumSystem(unittest.TestCase):
frozenset({'b', 'd'}): 1 / 4,
})
sigma = QuorumSystem(reads=a*b+c*d+e*f).uniform_strategy(f=1)
self.assertEqual(sigma.sigma_r, {
frozenset({'a', 'b', 'c', 'd'}): 1 / 3,
frozenset({'a', 'b', 'e', 'f'}): 1 / 3,
frozenset({'c', 'd', 'e', 'f'}): 1 / 3,
})
self.assertEqual(sigma.sigma_w, {
frozenset({'a', 'b', 'c', 'd', 'e', 'f'}): 1,
})
def test_make_strategy(self):
a = Node('a')
b = Node('b')