petter2025 commited on
Commit
ca98764
·
verified ·
1 Parent(s): e23e5b1

Create conftest.py

Browse files
Files changed (1) hide show
  1. conftest.py +141 -0
conftest.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Pytest configuration and shared fixtures
3
+ """
4
+
5
+ import pytest
6
+ import tempfile
7
+ import os
8
+ from datetime import datetime, timezone
9
+ from models import ReliabilityEvent, EventSeverity, HealingPolicy, HealingAction, PolicyCondition
10
+ from healing_policies import PolicyEngine
11
+ from app import (
12
+ ThreadSafeEventStore,
13
+ AdvancedAnomalyDetector,
14
+ BusinessImpactCalculator,
15
+ SimplePredictiveEngine,
16
+ EnhancedReliabilityEngine,
17
+ OrchestrationManager
18
+ )
19
+
20
+
21
+ @pytest.fixture
22
+ def sample_event():
23
+ """Create a sample reliability event for testing"""
24
+ return ReliabilityEvent(
25
+ component="test-service",
26
+ latency_p99=250.0,
27
+ error_rate=0.08,
28
+ throughput=1000.0,
29
+ cpu_util=0.75,
30
+ memory_util=0.65,
31
+ severity=EventSeverity.MEDIUM
32
+ )
33
+
34
+
35
+ @pytest.fixture
36
+ def critical_event():
37
+ """Create a critical reliability event"""
38
+ return ReliabilityEvent(
39
+ component="critical-service",
40
+ latency_p99=600.0,
41
+ error_rate=0.35,
42
+ throughput=500.0,
43
+ cpu_util=0.95,
44
+ memory_util=0.92,
45
+ severity=EventSeverity.CRITICAL
46
+ )
47
+
48
+
49
+ @pytest.fixture
50
+ def normal_event():
51
+ """Create a normal (healthy) reliability event"""
52
+ return ReliabilityEvent(
53
+ component="healthy-service",
54
+ latency_p99=80.0,
55
+ error_rate=0.01,
56
+ throughput=2000.0,
57
+ cpu_util=0.40,
58
+ memory_util=0.35,
59
+ severity=EventSeverity.LOW
60
+ )
61
+
62
+
63
+ @pytest.fixture
64
+ def sample_policy():
65
+ """Create a sample healing policy"""
66
+ return HealingPolicy(
67
+ name="test_policy",
68
+ conditions=[
69
+ PolicyCondition(metric="latency_p99", operator="gt", threshold=300.0)
70
+ ],
71
+ actions=[HealingAction.RESTART_CONTAINER],
72
+ priority=2,
73
+ cool_down_seconds=60,
74
+ max_executions_per_hour=5
75
+ )
76
+
77
+
78
+ @pytest.fixture
79
+ def policy_engine():
80
+ """Create a fresh policy engine for testing"""
81
+ return PolicyEngine(max_cooldown_history=100, max_execution_history=100)
82
+
83
+
84
+ @pytest.fixture
85
+ def event_store():
86
+ """Create a fresh event store"""
87
+ return ThreadSafeEventStore(max_size=100)
88
+
89
+
90
+ @pytest.fixture
91
+ def anomaly_detector():
92
+ """Create a fresh anomaly detector"""
93
+ return AdvancedAnomalyDetector()
94
+
95
+
96
+ @pytest.fixture
97
+ def business_calculator():
98
+ """Create a business impact calculator"""
99
+ return BusinessImpactCalculator()
100
+
101
+
102
+ @pytest.fixture
103
+ def predictive_engine():
104
+ """Create a predictive engine"""
105
+ return SimplePredictiveEngine(history_window=20)
106
+
107
+
108
+ @pytest.fixture
109
+ def temp_dir():
110
+ """Create a temporary directory for test files"""
111
+ with tempfile.TemporaryDirectory() as tmpdir:
112
+ yield tmpdir
113
+
114
+
115
+ @pytest.fixture
116
+ def mock_faiss_index(temp_dir):
117
+ """Create a mock FAISS index for testing"""
118
+ # This would require FAISS to be installed
119
+ # For now, return None to allow tests to skip FAISS operations
120
+ return None
121
+
122
+
123
+ @pytest.fixture
124
+ async def reliability_engine(
125
+ policy_engine,
126
+ event_store,
127
+ anomaly_detector,
128
+ business_calculator
129
+ ):
130
+ """Create a fully initialized reliability engine"""
131
+ orchestrator = OrchestrationManager()
132
+
133
+ engine = EnhancedReliabilityEngine(
134
+ orchestrator=orchestrator,
135
+ policy_engine=policy_engine,
136
+ event_store=event_store,
137
+ anomaly_detector=anomaly_detector,
138
+ business_calculator=business_calculator
139
+ )
140
+
141
+ return engine