Browse Source

Try harder to clean up after the browsers.

Rob Sayre 14 years ago
parent
commit
2b6b6d5ab2
  1. 16
      test/test.py

16
test/test.py

@ -139,6 +139,7 @@ class BrowserCommand():
self.name = browserRecord["name"] self.name = browserRecord["name"]
self.path = browserRecord["path"] self.path = browserRecord["path"]
self.tempDir = None self.tempDir = None
self.process = None
if platform.system() == "Darwin" and (self.path.endswith(".app") or self.path.endswith(".app/")): if platform.system() == "Darwin" and (self.path.endswith(".app") or self.path.endswith(".app/")):
self._fixupMacPath() self._fixupMacPath()
@ -156,6 +157,17 @@ class BrowserCommand():
self.profileDir) self.profileDir)
def teardown(self): def teardown(self):
# If the browser is still running, wait up to ten seconds for it to quit
if self.process and self.process.poll() is None:
checks = 0
while self.process.poll() is None and checks < 20:
checks += 1
time.sleep(.5)
# If it's still not dead, try to kill it
if self.process.poll() is None:
print "Process %s is still running. Killing." % self.name
self.process.kill()
if self.tempDir is not None and os.path.exists(self.tempDir): if self.tempDir is not None and os.path.exists(self.tempDir):
shutil.rmtree(self.tempDir) shutil.rmtree(self.tempDir)
@ -164,7 +176,7 @@ class BrowserCommand():
if platform.system() == "Darwin": if platform.system() == "Darwin":
cmds.append("-foreground") cmds.append("-foreground")
cmds.extend(["-no-remote", "-profile", self.profileDir, url]) cmds.extend(["-no-remote", "-profile", self.profileDir, url])
subprocess.Popen(cmds) self.process = subprocess.Popen(cmds)
def makeBrowserCommands(browserManifestFile): def makeBrowserCommands(browserManifestFile):
with open(browserManifestFile) as bmf: with open(browserManifestFile) as bmf:
@ -239,6 +251,8 @@ def teardownBrowsers(browsers):
b.teardown() b.teardown()
except: except:
print "Error cleaning up after browser at ", b.path print "Error cleaning up after browser at ", b.path
print "Temp dir was ", b.tempDir
print "Error:", sys.exc_info()[0]
def check(task, results, browser): def check(task, results, browser):
failed = False failed = False

Loading…
Cancel
Save