Commit ce2c778f authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Wait for all chrome.exe processes to exit before cleaning up.

test_chrome_with_chromedriver.py sometimes fails to delete the user data
dir because lingering chrome.exe processes (e.g., the crashpad handler)
are still working in it. This change causes the test to wait for all
Chrome procs to exit before searching for crash reports and cleaning up.

BUG=907979

Change-Id: I6500973a906a7b71b36d44aae4c1ca50d42f2001
Reviewed-on: https://chromium-review.googlesource.com/c/1352177
Commit-Queue: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611616}
parent bb76eacb
......@@ -36,6 +36,43 @@ def GetProcessIDs(process_path):
path == process_path]
def WaitForChromeExit():
"""Waits for all chrome.exe processes to exit."""
def GetChromeProcesses():
"""Returns a dict of all chrome.exe processes indexed by pid."""
chrome_processes = dict()
for process in psutil.process_iter():
try:
if process.name == 'chrome.exe':
chrome_processes[process.pid] = process
except psutil.Error:
pass
return chrome_processes
def GetBrowserProcess(chrome_processes):
"""Returns a psutil.Process for the browser process in |chrome_processes|.
"""
# Find the one whose parent isn't a chrome.exe process.
for process in chrome_processes.itervalues():
try:
if process.ppid not in chrome_processes:
return process
except psutil.Error:
pass
return None
chrome_processes = GetChromeProcesses()
while chrome_processes:
# Prefer waiting on the browser process.
process = GetBrowserProcess(chrome_processes)
if not process:
# Pick any process to wait on if no top-level parent was found.
process = next(chrome_processes.itervalues())
process.wait()
# Check for stragglers and keep waiting until all are gone.
chrome_processes = GetChromeProcesses()
def GetWindowHandles(process_ids):
"""Returns a list of handles of windows owned by processes in |process_ids|.
......
......@@ -21,6 +21,8 @@ import sys
import tempfile
import time
import chrome_helper
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
SRC_DIR = os.path.join(THIS_DIR, '..', '..', '..')
WEBDRIVER_PATH = os.path.join(
......@@ -106,6 +108,7 @@ def CreateChromedriver(args):
finally:
if driver:
driver.quit()
chrome_helper.WaitForChromeExit()
# To help with local crash analysis, change None to tempfile.gettempdir().
# TODO(grt): Copy crash dumps into ${ISOLATED_OUTDIR}.
CollectCrashReports(user_data_dir, None)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment