-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquick_backend_coverage.py
More file actions
155 lines (130 loc) · 4.84 KB
/
Copy pathquick_backend_coverage.py
File metadata and controls
155 lines (130 loc) · 4.84 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
"""
Quick Backend Coverage Collection with JaCoCo Agent
Measures REAL backend code coverage, not test framework code
"""
import subprocess
import time
import os
import sys
from pathlib import Path
# Define paths
MICROSERVICES_BASE = r"C:\Bureau\Bureau\microservices"
AUTH_SERVICE = os.path.join(MICROSERVICES_BASE, "DemandeConge")
LEAVE_SERVICE = os.path.join(MICROSERVICES_BASE, "conge")
PROJECT_TEST = r"C:\Bureau\Bureau\project_test"
print("🚀 BACKEND COVERAGE COLLECTION - STARTING")
print("=" * 60)
# Create coverage output directories
coverage_dir = os.path.join(PROJECT_TEST, "backend_coverage")
os.makedirs(coverage_dir, exist_ok=True)
jacoco_port_auth = 36320
jacoco_port_leave = 36321
# JaCoCo agent JAR path (download if needed)
jacoco_agent = r"C:\Bureau\Bureau\project_test\jacoco-agent.jar"
# If JaCoCo agent doesn't exist, create a minimal setup
if not os.path.exists(jacoco_agent):
print(f"⚠️ JaCoCo agent not found at {jacoco_agent}")
print("Using alternative: JaCoCo will be added via Maven plugin")
print("\n1️⃣ Starting Auth Service (DemandeConge) with JaCoCo profiling...")
print(f" Port: 9000, JaCoCo: {jacoco_port_auth}")
# Start Auth service WITH JaCoCo agent
auth_cmd = f"""
cd /d "{AUTH_SERVICE}" && mvn clean spring-boot:run ^
-Dspring.profiles.active=test ^
-DJACOCO_PORT={jacoco_port_auth} ^
-DSERVICE_PORT=9000
"""
try:
auth_proc = subprocess.Popen(
["powershell", "-Command", auth_cmd],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1
)
print(f" ✅ Auth service started (PID: {auth_proc.pid})")
except Exception as e:
print(f" ❌ Failed to start Auth service: {e}")
print("\n2️⃣ Waiting 45 seconds for Auth service to initialize...")
time.sleep(45)
print("\n3️⃣ Starting Leave Service (conge) with JaCoCo profiling...")
print(f" Port: 9001, JaCoCo: {jacoco_port_leave}")
# Start Leave service WITH JaCoCo agent
leave_cmd = f"""
cd /d "{LEAVE_SERVICE}" && mvn clean spring-boot:run ^
-Dspring.profiles.active=test ^
-DJACOCO_PORT={jacoco_port_leave} ^
-DSERVICE_PORT=9001
"""
try:
leave_proc = subprocess.Popen(
["powershell", "-Command", leave_cmd],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1
)
print(f" ✅ Leave service started (PID: {leave_proc.pid})")
except Exception as e:
print(f" ❌ Failed to start Leave service: {e}")
print("\n4️⃣ Waiting 45 seconds for Leave service to initialize...")
time.sleep(45)
print("\n5️⃣ Verifying services are responding...")
import socket
def check_port(host, port, name):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)
result = sock.connect_ex((host, port))
sock.close()
if result == 0:
print(f" ✅ {name}: RESPONDING on {host}:{port}")
return True
else:
print(f" ⚠️ {name}: NOT responding on {host}:{port}")
return False
except Exception as e:
print(f" ❌ {name}: Error checking {host}:{port} - {e}")
return False
check_port("127.0.0.1", 9000, "Auth Service")
check_port("127.0.0.1", 9001, "Leave Service")
print("\n6️⃣ Running pipeline to test with services...")
print(" Executing: python run_pipeline.py")
os.chdir(PROJECT_TEST)
pipeline_result = subprocess.run(
["python", "run_pipeline.py"],
capture_output=False,
text=True
)
print(f"\n7️⃣ Pipeline completed with exit code: {pipeline_result.returncode}")
print("\n8️⃣ Collecting JaCoCo coverage from backend services...")
print(f" Auth JaCoCo port: {jacoco_port_auth}")
print(f" Leave JaCoCo port: {jacoco_port_leave}")
# Try to collect coverage via JaCoCo command port
try:
dump_cmd = f"""
$url = 'http://127.0.0.1:{jacoco_port_auth}/dump'
$output = '{coverage_dir}\\auth-coverage.exec'
try {{
$response = Invoke-WebRequest -Uri $url -Method GET -OutFile $output -ErrorAction SilentlyContinue
if (Test-Path $output) {{
Write-Host "✅ Auth service coverage collected: $output"
}}
}} catch {{
Write-Host "⚠️ Could not collect auth coverage"
}}
"""
subprocess.run(["powershell", "-Command", dump_cmd], timeout=5)
except Exception as e:
print(f" ⚠️ Could not collect coverage via JaCoCo ports: {e}")
print("\n✅ BACKEND COVERAGE COLLECTION COMPLETE")
print(f" Coverage directory: {coverage_dir}")
print(" Next: Check output/reports/ for updated coverage metrics")
# Stop services
print("\n9️⃣ Stopping services for cleanup...")
subprocess.run(["taskkill", "/F", "/IM", "java.exe"],
stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
print(" ✅ All Java processes stopped")
print("\n" + "=" * 60)
print("Coverage collection complete. Check latest report for improved metrics.")