fix(ci): clean up flutter test processes
This commit is contained in:
@@ -33,31 +33,114 @@ jobs:
|
|||||||
- name: Ejecutar tests críticos
|
- name: Ejecutar tests críticos
|
||||||
run: |
|
run: |
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
'test/servicios/servicio_programacion_alarmas_test.dart',
|
'test/servicios/servicio_programacion_alarmas_test.dart',
|
||||||
'test/estado/estado_alarmas_test.dart',
|
'test/estado/estado_alarmas_test.dart',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
use_process_group = hasattr(os, 'killpg') and os.name != 'nt'
|
||||||
|
|
||||||
|
def cleanup_process_group(pid):
|
||||||
|
if not use_process_group:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
os.killpg(pid, signal.SIGTERM)
|
||||||
|
time.sleep(1)
|
||||||
|
os.killpg(pid, signal.SIGKILL)
|
||||||
|
except ProcessLookupError:
|
||||||
|
pass
|
||||||
|
|
||||||
for test_path in tests:
|
for test_path in tests:
|
||||||
cmd = [
|
cmd = [
|
||||||
'flutter',
|
'flutter',
|
||||||
'test',
|
'test',
|
||||||
|
'--no-pub',
|
||||||
'--concurrency=1',
|
'--concurrency=1',
|
||||||
'--timeout=60s',
|
'--timeout=60s',
|
||||||
'--reporter=expanded',
|
'--reporter=expanded',
|
||||||
test_path,
|
test_path,
|
||||||
]
|
]
|
||||||
print('$ ' + ' '.join(cmd), flush=True)
|
print('$ ' + ' '.join(cmd), flush=True)
|
||||||
|
process = subprocess.Popen(cmd, start_new_session=use_process_group)
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(cmd, timeout=180)
|
returncode = process.wait(timeout=180)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
print(f'ERROR: timeout ejecutando {test_path}', file=sys.stderr, flush=True)
|
print(f'ERROR: timeout ejecutando {test_path}', file=sys.stderr, flush=True)
|
||||||
|
cleanup_process_group(process.pid)
|
||||||
sys.exit(124)
|
sys.exit(124)
|
||||||
if result.returncode != 0:
|
finally:
|
||||||
sys.exit(result.returncode)
|
cleanup_process_group(process.pid)
|
||||||
|
|
||||||
|
if returncode != 0:
|
||||||
|
sys.exit(returncode)
|
||||||
|
PY
|
||||||
|
|
||||||
|
- name: Limpiar procesos Flutter de tests
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
python3 - <<'PY'
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
workspace = os.getcwd()
|
||||||
|
test_paths = (
|
||||||
|
'test/estado/estado_alarmas_test.dart',
|
||||||
|
'test/servicios/servicio_programacion_alarmas_test.dart',
|
||||||
|
)
|
||||||
|
patterns = (
|
||||||
|
'flutter_tester',
|
||||||
|
'flutter_tools.snapshot',
|
||||||
|
'frontend_server',
|
||||||
|
'dartvm',
|
||||||
|
'dartaotruntime',
|
||||||
|
) + test_paths
|
||||||
|
current_pid = os.getpid()
|
||||||
|
ps = subprocess.run(
|
||||||
|
['ps', '-axww', '-o', 'pid=', '-o', 'command='],
|
||||||
|
text=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
killed = []
|
||||||
|
for raw in ps.stdout.splitlines():
|
||||||
|
line = raw.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
pid_text, _, command = line.partition(' ')
|
||||||
|
try:
|
||||||
|
pid = int(pid_text)
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
if pid == current_pid:
|
||||||
|
continue
|
||||||
|
if workspace not in command and not any(path in command for path in test_paths):
|
||||||
|
continue
|
||||||
|
if not any(pattern in command for pattern in patterns):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
os.kill(pid, signal.SIGTERM)
|
||||||
|
killed.append(pid)
|
||||||
|
except ProcessLookupError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if killed:
|
||||||
|
print('Procesos Flutter de test terminados: ' + ', '.join(map(str, killed)))
|
||||||
|
time.sleep(1)
|
||||||
|
for pid in killed:
|
||||||
|
try:
|
||||||
|
os.kill(pid, signal.SIGKILL)
|
||||||
|
except ProcessLookupError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print('No quedaron procesos Flutter de test vivos')
|
||||||
PY
|
PY
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
|||||||
Reference in New Issue
Block a user