def test_proposer_ignores_decending_promise(self): self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='A', value="a_1"), self.channel) self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='B', value="a_1"), self.channel) self.assertEqual(self.role.highest_proposal, Proposal('A', 1)) self.role.receive(Promise.create(proposal=Proposal('A', 0), sender='A', value="a_0"), self.channel) self.assertEqual(self.role.highest_proposal, Proposal('A', 1)) self.assertEqual(self.channel.broadcast_messages[-1].value, "a_1")
def test_node_receives_higher_proposals(self): self.assertEqual(self.state.read(Node.PROPOSED), Proposal(None, 0)) self.role.receive(Prepare.create(proposal=Proposal('A', 1)), self.channel) self.assertEqual(self.state.read(Node.PROPOSED), Proposal('A', 2)) self.role.receive(Promise.create(proposal=Proposal('A', 3)), self.channel) self.assertEqual(self.state.read(Node.PROPOSED), Proposal('A', 4)) self.role.receive(Accept.create(proposal=Proposal('A', 5)), self.channel) self.assertEqual(self.state.read(Node.PROPOSED), Proposal('A', 6)) self.role.receive(Accepted.create(proposal=Proposal('A', 7)), self.channel) self.assertEqual(self.state.read(Node.PROPOSED), Proposal('A', 8))
def test_proposer_ignores_duplicate_promises(self): self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='A'), self.channel) self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='A'), self.channel) self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='A'), self.channel) self.assertEqual(len(self.channel.broadcast_messages), 0)
def test_proposer_doesnt_receive_quorum_or_promises(self): self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='A'), self.channel) self.assertEqual(len(self.channel.broadcast_messages), 0)
def test_proposer_receives_quorum_of_promises(self): self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='A'), self.channel) self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='B'), self.channel) self.role.receive(Promise.create(proposal=Proposal('A', 1), sender='C'), self.channel) self.assertTrue(type(self.channel.broadcast_messages[-1]) is Accept)