def test_load_metrics_from_kv_store_can_load_all_values(storage): events = generate_events(10) step = timedelta(seconds=5) ts = MockTimestamp() metrics = KvStoreMetricsCollector(storage, ts) expected_stats = MetricsStats(step) for ev in events: ts.value = ev.timestamp metrics.store_event(ev.name, ev.value) expected_stats.add(ev.timestamp, ev.name, ev.value) stats = load_metrics_from_kv_store(storage, step=step) assert stats == expected_stats
def test_equal_votes_dont_accumulate_when_added(instance_changes, tconf): frm = "Node1" view_no = 1 time_provider = MockTimestamp(0) second_vote_time = 1 instance_changes = InstanceChanges(tconf, time_provider) msg = InstanceChange(view_no, Suspicions.PRIMARY_DEGRADED.code) instance_changes.add_vote(msg, frm) time_provider.value = second_vote_time instance_changes.add_vote(msg, frm) assert instance_changes[view_no].voters[frm] == second_vote_time assert len(instance_changes[view_no].voters) == 1 assert len(instance_changes) == 1
def test_load_metrics_from_kv_store_can_filter_values(storage): events = generate_events(10) step = timedelta(seconds=3) ts = MockTimestamp() metrics = KvStoreMetricsCollector(storage, ts) expected_stats = MetricsStats(step) timestamps = sorted(ev.timestamp for ev in events) min_ts = timestamps[len(events) // 3] max_ts = timestamps[2 * len(events) // 3] for ev in events: ts.value = ev.timestamp metrics.store_event(ev.name, ev.value) if min_ts <= ev.timestamp <= max_ts: expected_stats.add(ev.timestamp, ev.name, ev.value) stats = load_metrics_from_kv_store(storage, min_ts, max_ts, step) assert stats == expected_stats
def test_old_ic_discard(instance_changes, tconf): frm = "Node1" view_no = 1 quorum = 2 time_provider = MockTimestamp(0) instance_changes = InstanceChanges(tconf, time_provider) msg = InstanceChange(view_no, Suspicions.PRIMARY_DEGRADED.code) time_provider.value = 0 instance_changes.add_vote(msg, frm) time_provider.value += tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL + 1 assert not instance_changes.has_view(view_no) instance_changes.add_vote(msg, frm) time_provider.value += tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL + 1 assert not instance_changes.has_inst_chng_from(view_no, frm) instance_changes.add_vote(msg, frm) time_provider.value += tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL + 1 assert not instance_changes.has_quorum(view_no, quorum)
def test_kv_store_metrics_collector_store_all_data_in_order( storage: KeyValueStorage): ts = MockTimestamp() metrics = KvStoreMetricsCollector(storage, ts) events = generate_events(10) for e in events: ts.value = e.timestamp metrics.store_event(e.name, e.value) stored_events = [ KvStoreMetricsFormat.decode(k, v) for k, v in storage.iterator() ] # Check that all events are stored assert len(stored_events) == len(events) # Check that all events are stored in correct order assert sorted(stored_events, key=lambda v: v.timestamp) == stored_events # Check that all events stored were in source events for ev in stored_events: assert ev in events # Check that all source events are in stored events for ev in events: assert ev in stored_events