From 490b7d35ea75cd0f84da68be3084144c3f314fca Mon Sep 17 00:00:00 2001 From: Michael Whittaker Date: Mon, 7 Jun 2021 08:49:12 -0700 Subject: [PATCH] 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! --- quoracle/quorum_system.py | 2 +- tests/test_quorum_system.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/quoracle/quorum_system.py b/quoracle/quorum_system.py index 920384b..ef2cf40 100644 --- a/quoracle/quorum_system.py +++ b/quoracle/quorum_system.py @@ -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') diff --git a/tests/test_quorum_system.py b/tests/test_quorum_system.py index b8f68ee..d8e4bfb 100644 --- a/tests/test_quorum_system.py +++ b/tests/test_quorum_system.py @@ -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')