Merge pull request #75 from sayrer/master
Run the browsers in parallel, and try hard to clean up after them
This commit is contained in:
commit
a12962302e
@ -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
|
||||
|
52
test/test.py
52
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,8 @@ class BrowserCommand():
|
||||
def __init__(self, browserRecord):
|
||||
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()
|
||||
@ -151,19 +153,30 @@ 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 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)
|
||||
|
||||
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)
|
||||
self.process = subprocess.Popen(cmds)
|
||||
|
||||
def makeBrowserCommands(browserManifestFile):
|
||||
with open(browserManifestFile) as bmf:
|
||||
@ -223,14 +236,23 @@ def setUp(options):
|
||||
|
||||
State.remaining = len(testBrowsers) * len(manifestList)
|
||||
|
||||
for b in testBrowsers:
|
||||
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.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()
|
||||
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
|
||||
@ -385,8 +407,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()
|
||||
|
Loading…
Reference in New Issue
Block a user