Skip to content

Commit 850c46c

Browse files
committed
[FIX] tests: catch remain processes
In some case a process could remain aive at the end of a tests In addition to possible race condition, this can also cause a program to remain stuck at the end of the tests. This commit proposes to - catch all remaining processes at the end of a base case. - log a message if a process is found at the shutdown of the server. closes odoo#232424 X-original-commit: 5f7f138 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
1 parent 43cea87 commit 850c46c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

odoo/service/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ def stop(self):
653653
_logger.info("Logging uses the database, stop logging then close DB connections")
654654
log_ctx = mute_logger('')
655655

656+
current_process = psutil.Process()
657+
children = current_process.children(recursive=False)
658+
for child in children:
659+
_logger.info('A child process was found, pid is %s, process may hang', child)
660+
656661
with log_ctx:
657662
sql_db.close_all()
658663
_logger.debug('--')

odoo/tests/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pathlib
2020
import platform
2121
import pprint
22+
import psutil
2223
import re
2324
import shutil
2425
import signal
@@ -382,6 +383,15 @@ def run(self, result: OdooTestResult) -> None:
382383

383384
@classmethod
384385
def setUpClass(cls):
386+
def check_remaining_processes():
387+
current_process = psutil.Process()
388+
children = current_process.children(recursive=False)
389+
for child in children:
390+
_logger.warning('A child process was found, terminating it: %s', child)
391+
child.terminate()
392+
psutil.wait_procs(children, timeout=10) # mainly to avoid a zombie process that would be logged again at the end.
393+
cls.addClassCleanup(check_remaining_processes)
394+
385395
def check_remaining_patchers():
386396
for patcher in _patch._active_patches:
387397
_logger.warning("A patcher (targeting %s.%s) was remaining active at the end of %s, disabling it...", patcher.target, patcher.attribute, cls.__name__)

0 commit comments

Comments
 (0)