async def _test_wreak_havoc(self): num_ops = 500 for c in bft.interesting_configs(): print(f"\n\nStarting test with configuration={c}", flush=True) config = bft.TestConfig(c['n'], c['f'], c['c'], c['num_clients'], key_file_prefix=KEY_FILE_PREFIX, start_replica_cmd=start_replica_cmd) with bft.BftTestNetwork(config) as bft_network: self.skvbc = kvbc.SimpleKVBCProtocol(bft_network) init_state = self.skvbc.initial_state() self.tracker = skvbc_history_tracker.SkvbcTracker(init_state) self.bft_network = bft_network self.status = Status(c) await bft_network.init() bft_network.start_all_replicas() async with trio.open_nursery() as nursery: nursery.start_soon(self.run_concurrent_ops, num_ops) nursery.start_soon(self.crash_primary) await self.verify() time.sleep(2)
async def test_healthy(self, bft_network): """ Run a bunch of concurrrent requests in batches and verify linearizability. The system is healthy and stable and no faults are intentionally generated. """ num_ops = 500 self.skvbc = kvbc.SimpleKVBCProtocol(bft_network) init_state = self.skvbc.initial_state() self.tracker = skvbc_history_tracker.SkvbcTracker(init_state) self.bft_network = bft_network self.status = Status(bft_network.config) bft_network.start_all_replicas() async with trio.open_nursery() as nursery: nursery.start_soon(self.run_concurrent_ops, num_ops) await self.verify()
async def test_wreak_havoc(self, bft_network): """ Run a bunch of concurrrent requests in batches and verify linearizability. In this test we generate faults periodically and verify linearizability at the end of the run. """ num_ops = 500 self.skvbc = kvbc.SimpleKVBCProtocol(bft_network) init_state = self.skvbc.initial_state() self.tracker = skvbc_history_tracker.SkvbcTracker(init_state) self.bft_network = bft_network self.status = Status(bft_network.config) bft_network.start_all_replicas() async with trio.open_nursery() as nursery: nursery.start_soon(self.run_concurrent_ops, num_ops) nursery.start_soon(self.crash_primary) await self.verify()
def test_num_blocks_to_linearize_over(self): """ Create a tracker with enough information to allow running _num_blocks_to_linearize_over. Verify that the correct number of blocks is returned. """ req_index = 14 last_known_block = 6 last_consecutive_block = 3 missing_intermediate_blocks = 2 kvpairs = {'a': 1, 'b': 2, 'c': 3} cs = skvbc_history_tracker.CausalState(req_index, last_known_block, last_consecutive_block, missing_intermediate_blocks, kvpairs) is_read = False write = skvbc_history_tracker.ConcurrentValue(is_read) tracker = skvbc_history_tracker.SkvbcTracker() tracker.concurrent[req_index] = \ {2: write, 4: write, 7: write, 11: write, 16: write} tracker.last_known_block = 7 self.assertEqual(1, tracker._num_blocks_to_linearize_over(req_index, cs)) tracker.last_known_block = 8 self.assertEqual(2, tracker._num_blocks_to_linearize_over(req_index, cs)) tracker.last_known_block = 9 self.assertEqual(3, tracker._num_blocks_to_linearize_over(req_index, cs)) tracker.last_known_block = 10 self.assertEqual(3, tracker._num_blocks_to_linearize_over(req_index, cs)) tracker.last_known_block = 11 self.assertEqual(3, tracker._num_blocks_to_linearize_over(req_index, cs))
async def _test_healthy(self): num_ops = 500 for c in bft.interesting_configs(): config = bft.TestConfig(c['n'], c['f'], c['c'], c['num_clients'], key_file_prefix=KEY_FILE_PREFIX, start_replica_cmd=start_replica_cmd) with bft.BftTestNetwork(config) as bft_network: self.skvbc = kvbc.SimpleKVBCProtocol(bft_network) init_state = self.skvbc.initial_state() self.tracker = skvbc_history_tracker.SkvbcTracker(init_state) self.bft_network = bft_network self.status = Status(c) await bft_network.init() bft_network.start_all_replicas() async with trio.open_nursery() as nursery: nursery.start_soon(self.run_concurrent_ops, num_ops) await self.verify()
async def test_while_dropping_packets(self, bft_network): """ Run a bunch of concurrrent requests in batches and verify linearizability, while dropping a small amount of packets between all replicas. """ num_ops = 500 with net.PacketDroppingAdversary(bft_network, drop_rate_percentage=5) as adversary: self.skvbc = kvbc.SimpleKVBCProtocol(bft_network) init_state = self.skvbc.initial_state() self.tracker = skvbc_history_tracker.SkvbcTracker(init_state) self.bft_network = bft_network self.status = Status(bft_network.config) bft_network.start_all_replicas() adversary.interfere() async with trio.open_nursery() as nursery: nursery.start_soon(self.run_concurrent_ops, num_ops) await self.verify()
def setUp(self): super().setUp() self.tracker = skvbc_history_tracker.SkvbcTracker()