From 6446b6d03a6138e5693516d7df1e295e51a25971 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Fri, 24 Jun 2011 08:43:26 -0700 Subject: [PATCH 1/3] Run browsers in parallel. No limit on the number of concurrent browsers right now. --- test/test.py | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/test/test.py b/test/test.py index 53f65f78b..7e678bd90 100644 --- a/test/test.py +++ b/test/test.py @@ -1,4 +1,4 @@ -import json, platform, os, shutil, sys, subprocess, tempfile, threading, urllib, urllib2 +import json, platform, os, shutil, sys, subprocess, tempfile, threading, time, urllib, urllib2 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import SocketServer from optparse import OptionParser @@ -138,6 +138,7 @@ class BrowserCommand(): def __init__(self, browserRecord): self.name = browserRecord["name"] self.path = browserRecord["path"] + self.tempDir = None if platform.system() == "Darwin" and (self.path.endswith(".app") or self.path.endswith(".app/")): self._fixupMacPath() @@ -151,19 +152,19 @@ class BrowserCommand(): def setup(self): self.tempDir = tempfile.mkdtemp() self.profileDir = os.path.join(self.tempDir, "profile") - print self.profileDir shutil.copytree(os.path.join(DOC_ROOT, "test", "resources", "firefox"), self.profileDir) def teardown(self): - shutil.rmtree(self.tempDir) + if self.tempDir is not None and os.path.exists(self.tempDir): + shutil.rmtree(self.tempDir) def start(self, url): cmds = [self.path] if platform.system() == "Darwin": cmds.append("-foreground") cmds.extend(["-no-remote", "-profile", self.profileDir, url]) - subprocess.call(cmds) + subprocess.Popen(cmds) def makeBrowserCommands(browserManifestFile): with open(browserManifestFile) as bmf: @@ -223,15 +224,22 @@ def setUp(options): State.remaining = len(testBrowsers) * len(manifestList) - for b in testBrowsers: - try: - b.setup() - print 'Launching', b.name - qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile) - b.start('http://localhost:8080/test/test_slave.html?'+ qs) - finally: - b.teardown() + return testBrowsers +def startBrowsers(browsers, options): + for b in browsers: + b.setup() + print 'Launching', b.name + qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile) + b.start('http://localhost:8080/test/test_slave.html?'+ qs) + +def teardownBrowsers(browsers): + for b in browsers: + try: + b.teardown() + except: + print "Error cleaning up after browser at ", b.path + def check(task, results, browser): failed = False for r in xrange(len(results)): @@ -385,8 +393,14 @@ def main(): httpd_thread.setDaemon(True) httpd_thread.start() - setUp(options) - processResults() + browsers = setUp(options) + try: + startBrowsers(browsers, options) + while not State.done: + time.sleep(1) + processResults() + finally: + teardownBrowsers(browsers) if __name__ == '__main__': main() From a67a4c0677abfd191de0330e18507f834315e7b3 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Fri, 24 Jun 2011 09:00:13 -0700 Subject: [PATCH 2/3] Add a line to prevent TestPilot from installing. --- test/resources/firefox/user.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/resources/firefox/user.js b/test/resources/firefox/user.js index d4b9d4130..7ca293923 100644 --- a/test/resources/firefox/user.js +++ b/test/resources/firefox/user.js @@ -32,3 +32,4 @@ user_pref("app.update.enabled", false); user_pref("browser.panorama.experienced_first_run", true); // Assume experienced user_pref("dom.w3c_touch_events.enabled", true); user_pref("extensions.checkCompatibility", false); +user_pref("extensions.installDistroAddons", false); // prevent testpilot etc From 2b6b6d5ab23de0a99a54d824b0ab4dc4c7fe5af9 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Fri, 24 Jun 2011 09:45:41 -0700 Subject: [PATCH 3/3] Try harder to clean up after the browsers. --- test/test.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/test.py b/test/test.py index 7e678bd90..bc30d5f8a 100644 --- a/test/test.py +++ b/test/test.py @@ -139,6 +139,7 @@ class BrowserCommand(): self.name = browserRecord["name"] self.path = browserRecord["path"] self.tempDir = None + self.process = None if platform.system() == "Darwin" and (self.path.endswith(".app") or self.path.endswith(".app/")): self._fixupMacPath() @@ -156,6 +157,17 @@ class BrowserCommand(): self.profileDir) 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): shutil.rmtree(self.tempDir) @@ -164,7 +176,7 @@ class BrowserCommand(): if platform.system() == "Darwin": cmds.append("-foreground") cmds.extend(["-no-remote", "-profile", self.profileDir, url]) - subprocess.Popen(cmds) + self.process = subprocess.Popen(cmds) def makeBrowserCommands(browserManifestFile): with open(browserManifestFile) as bmf: @@ -239,7 +251,9 @@ def teardownBrowsers(browsers): b.teardown() except: 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): failed = False for r in xrange(len(results)):