Add sys import to test files and remove obsolete integration tests
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
- Add sys import to 29 test files across agent-coordinator, blockchain-event-bridge, blockchain-node, and coordinator-api - Remove apps/blockchain-event-bridge/tests/test_integration.py (obsolete bridge integration tests) - Remove apps/coordinator-api/tests/test_integration.py (obsolete API integration tests) - Implement GPU registration in marketplace_gpu.py with GPURegistry model persistence
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
"""Unit tests for multi-region load balancer service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from main import app, LoadBalancingRule, RegionHealth, LoadBalancingMetrics, GeographicRule
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_app_initialization():
|
||||
"""Test that the FastAPI app initializes correctly"""
|
||||
assert app is not None
|
||||
assert app.title == "AITBC Multi-Region Load Balancer"
|
||||
assert app.version == "1.0.0"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_load_balancing_rule_model():
|
||||
"""Test LoadBalancingRule model"""
|
||||
rule = LoadBalancingRule(
|
||||
rule_id="rule_123",
|
||||
name="Test Rule",
|
||||
algorithm="weighted_round_robin",
|
||||
target_regions=["us-east-1", "eu-west-1"],
|
||||
weights={"us-east-1": 0.5, "eu-west-1": 0.5},
|
||||
health_check_path="/health",
|
||||
failover_enabled=True,
|
||||
session_affinity=False
|
||||
)
|
||||
assert rule.rule_id == "rule_123"
|
||||
assert rule.name == "Test Rule"
|
||||
assert rule.algorithm == "weighted_round_robin"
|
||||
assert rule.failover_enabled is True
|
||||
assert rule.session_affinity is False
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_region_health_model():
|
||||
"""Test RegionHealth model"""
|
||||
health = RegionHealth(
|
||||
region_id="us-east-1",
|
||||
status="healthy",
|
||||
response_time_ms=45.5,
|
||||
success_rate=0.99,
|
||||
active_connections=100,
|
||||
last_check=datetime.utcnow()
|
||||
)
|
||||
assert health.region_id == "us-east-1"
|
||||
assert health.status == "healthy"
|
||||
assert health.response_time_ms == 45.5
|
||||
assert health.success_rate == 0.99
|
||||
assert health.active_connections == 100
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_load_balancing_metrics_model():
|
||||
"""Test LoadBalancingMetrics model"""
|
||||
metrics = LoadBalancingMetrics(
|
||||
balancer_id="lb_123",
|
||||
timestamp=datetime.utcnow(),
|
||||
total_requests=1000,
|
||||
requests_per_region={"us-east-1": 500, "eu-west-1": 500},
|
||||
average_response_time=50.5,
|
||||
error_rate=0.001,
|
||||
throughput=100.0
|
||||
)
|
||||
assert metrics.balancer_id == "lb_123"
|
||||
assert metrics.total_requests == 1000
|
||||
assert metrics.average_response_time == 50.5
|
||||
assert metrics.error_rate == 0.001
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_geographic_rule_model():
|
||||
"""Test GeographicRule model"""
|
||||
rule = GeographicRule(
|
||||
rule_id="geo_123",
|
||||
source_regions=["us-east", "us-west"],
|
||||
target_regions=["us-east-1", "us-west-1"],
|
||||
priority=1,
|
||||
latency_threshold_ms=50.0
|
||||
)
|
||||
assert rule.rule_id == "geo_123"
|
||||
assert rule.source_regions == ["us-east", "us-west"]
|
||||
assert rule.priority == 1
|
||||
assert rule.latency_threshold_ms == 50.0
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_load_balancing_rule_empty_weights():
|
||||
"""Test LoadBalancingRule with empty weights"""
|
||||
rule = LoadBalancingRule(
|
||||
rule_id="rule_123",
|
||||
name="Test Rule",
|
||||
algorithm="round_robin",
|
||||
target_regions=["us-east-1"],
|
||||
weights={},
|
||||
health_check_path="/health",
|
||||
failover_enabled=False,
|
||||
session_affinity=False
|
||||
)
|
||||
assert rule.weights == {}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_region_health_negative_response_time():
|
||||
"""Test RegionHealth with negative response time"""
|
||||
health = RegionHealth(
|
||||
region_id="us-east-1",
|
||||
status="healthy",
|
||||
response_time_ms=-45.5,
|
||||
success_rate=0.99,
|
||||
active_connections=100,
|
||||
last_check=datetime.utcnow()
|
||||
)
|
||||
assert health.response_time_ms == -45.5
|
||||
Reference in New Issue
Block a user