-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_simulation.py
More file actions
70 lines (52 loc) · 2.66 KB
/
test_simulation.py
File metadata and controls
70 lines (52 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""
Test script to verify the simulation service works correctly.
"""
import asyncio
import time
from backend.simulation.simulation_service import SimulationService
from backend.config_manager import ConfigManager
def test_simulation():
"""Test the simulation service to ensure it generates realistic data."""
print("Testing Network Performance Simulation Service...")
# Create simulation service
config_manager = ConfigManager()
config_manager.set("SIMULATION_MODE", True)
service = SimulationService(cache_duration=1.0)
print("\n1. Testing initial data collection...")
initial_data = service.get_all_metrics()
print(f" Interfaces: {len(initial_data['interfaces'])}")
print(f" Performance Metrics: {len(initial_data['performance_metrics'])}")
print(f" Hardware Info: {len(initial_data['hardware_info'])}")
print("\n2. Testing data refresh...")
time.sleep(1.5) # Wait for cache to potentially expire
refreshed_data = service.get_all_metrics()
print(f" New data collected after refresh")
print("\n3. Testing data variation (waiting 3 seconds)...")
first_data = service.get_performance_metrics()
time.sleep(3)
second_data = service.get_performance_metrics()
# Compare some values to ensure they're changing
if first_data and second_data:
first_metric = first_data[0] if first_data else None
second_metric = second_data[0] if second_data else None
if first_metric and second_metric:
print(f" First throughput: {first_metric.throughput}")
print(f" Second throughput: {second_metric.throughput}")
print(f" Values are different: {first_metric.throughput != second_metric.throughput}")
print("\n4. Testing simulation mode detection...")
print(f" Config manager simulation mode: {config_manager.is_simulation_mode()}")
print("\n5. Testing with NetworkMonitorService in simulation mode...")
# Temporarily set environment variable to simulate deployment
import os
os.environ["SIMULATION_MODE"] = "true"
from backend.api.services import NetworkMonitorService
service_with_config = NetworkMonitorService(cache_duration=1.0)
service_data = service_with_config.get_all_metrics()
print(f" Service interfaces: {len(service_data['interfaces'])}")
print(f" Service performance metrics: {len(service_data['performance_metrics'])}")
print(f" Service hardware info: {len(service_data['hardware_info'])}")
print("\nSimulation test completed successfully!")
return True
if __name__ == "__main__":
test_simulation()