def test_replication_lag(): # pylint: disable=protected-access now = datetime.now() status = { "db_time": now, "pg_is_in_recovery": True, "pg_last_xact_replay_timestamp": now, "pg_last_xlog_receive_location": "0/0000001", "pg_last_xlog_replay_location": "0/0000002", } result = ClusterMonitor._parse_status_query_result(status.copy()) assert result["replication_time_lag"] == 0.0 status["db_time"] += timedelta(seconds=50, microseconds=42) result = ClusterMonitor._parse_status_query_result(status.copy()) assert result["replication_time_lag"] == 50.000042 status["db_time"] = now + timedelta(hours=42) result = ClusterMonitor._parse_status_query_result(status.copy()) assert result["replication_time_lag"] == 151200.0