Created
May 11, 2010 20:06
-
-
Save josip/397784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: may be Apache 2.0 license-contaminated. | |
# (I haven't checked whether there is a significant license compatibility issue here.) | |
import os, logging | |
import tempfile | |
import windmill | |
from windmill.bin import admin_lib | |
from twisted.internet import defer | |
from foolscap.api import eventually | |
from allmydata.util import log, fileutil | |
from allmydata.scripts.create_node import create_node, create_introducer | |
from allmydata.scripts.startstop_node import do_start, do_stop | |
from time import sleep | |
class TiltingMixin: | |
# adapted from | |
# http://github.com/windmill/windmill/blob/master/windmill/authoring/unit.py | |
# http://github.com/windmill/windmill/blob/master/windmill/bin/shell_objects.py | |
def setUp(self): | |
self.tahoe_web_port = "9999" | |
self.browser_debugging = True | |
self.test_url = "/" | |
self.browserName = "firefox" | |
self.js_test_details = [] | |
fileutil.make_dirs("tilting") | |
self.root = os.path.join(os.path.abspath("."), "tilting") | |
self.public_html_path = os.path.join(self.root, "storage", "public_html") | |
self.settings = { | |
'EXIT_ON_DONE': True, | |
'CONSOLE_LOG_LEVEL': logging.CRITICAL} | |
self.configure() | |
log.msg("starting tahoe nodes") | |
self._start_tahoe_nodes() | |
log.msg("copying application") | |
self.copy_application() | |
log.msg("setting up Windmill for browser '%s'" % (self.browserName)) | |
windmill.block_exit = True | |
# Windmill loves to output all sorts of stuff | |
windmill.stdout = tempfile.TemporaryFile() | |
admin_lib.configure_global_settings(logging_on=False) | |
for (setting, value) in self.settings.iteritems(): | |
windmill.settings[setting] = value | |
windmill.settings['controllers'] = [] | |
windmill.settings['TEST_URL'] = 'http://127.0.0.1:%s/%s' % (self.tahoe_web_port, self.test_url) | |
self.shell_objects = admin_lib.setup() | |
self.jsonrpc = self.shell_objects['httpd'].jsonrpc_methods_instance | |
self.jsonrpc_app = self.shell_objects['httpd'].namespaces['windmill-jsonrpc'] | |
# Windmill prints success/failure statistics on its own | |
def _windmill_teardown(**kwargs): | |
admin_lib.teardown(admin_lib.shell_objects_dict) | |
windmill.runserver_running = False | |
sleep(.25) | |
#del self.jsonrpc_app.__dict__[u'teardown'] | |
self.jsonrpc_app.__dict__[u'teardown'] = _windmill_teardown | |
if self.settings['JAVASCRIPT_TEST_DIR']: | |
self._log_js_test_results() | |
log.msg("starting browser") | |
self.shell_objects['start_' + self.browserName]() | |
d = defer.Deferred() | |
admin_lib.on_ide_awake.append(lambda: eventually(d.callback, None)) | |
d.addCallback(lambda ign: log.msg("browser started")) | |
if self.browser_debugging: | |
self.xmlrpc = windmill.tools.make_xmlrpc_client() | |
d.addCallback(lambda ign: | |
self.xmlrpc.add_command({'method':'commands.setOptions', | |
'params':{'runTests':False, 'priority':'normal'}})) | |
return d | |
def tearDown(self): | |
windmill.block_exit = False | |
if self.browser_debugging: | |
self.xmlrpc.add_command({'method':'commands.setOptions', | |
'params':{'runTests':True, 'priority':'normal'}}) | |
else: | |
log.msg("shutting down browser '%s'" % (self.browserName)) | |
admin_lib.teardown(self.shell_objects) | |
log.msg("browser shutdown done") | |
log.msg("shutting down Tahoe nodes") | |
self._stop_tahoe_nodes() | |
log.msg("Tahoe nodes shut down") | |
fileutil.rm_dir("tilting") | |
def _start_tahoe_nodes(self): | |
out = os.tmpfile() | |
start_options = {'syslog': False, 'profile': None} | |
create_introducer("tilting/introducer", | |
{'nickname': 'tilting-test-introducer'}, out=out, err=out) | |
do_start("tilting/introducer", start_options, out=out, err=out) | |
furl_path = "tilting/introducer/introducer.furl" | |
while not os.path.isfile(furl_path): | |
sleep(1) | |
introducer_furl = fileutil.read(furl_path).strip() | |
create_node("tilting/storage", { | |
'introducer': introducer_furl, | |
'nickname': 'tilting-test-storage-node', | |
'webport': str(self.tahoe_web_port)}, out=out, err=out) | |
do_start("tilting/storage", start_options, out=out, err=out) | |
def _stop_tahoe_nodes(self): | |
out = os.tmpfile() | |
do_stop("tilting/introducer", out=out, err=out) | |
do_stop("tilting/storage", out=out, err=out) | |
def _log_js_test_results(self): | |
# Replaces Windmill's logging utility with custom one, | |
# this way, failures of JS tests can be reported to buildbots. | |
# Windmill is quite unusable as a library, | |
# but there's nothing that can't be patched :) | |
def _report_without_resolve(**kwargs): | |
self.jsonrpc._test_resolution_suite.report_without_resolve(*kwargs) | |
self.js_test_details.append(kwargs) | |
# TestSuite doesn't pickup these changes. | |
# suite_name = str(kwargs['suite_name']) | |
# def test_js_method(self): | |
# self.failUnless(kwargs['result'], kwargs['debug']) | |
# | |
# test_js_method.__name__ = suite_name | |
# | |
# self.__dict__[suite_name] = test_js_method | |
return 200 | |
del self.jsonrpc_app.__dict__[u'report_without_resolve'] | |
self.jsonrpc_app.register_method(_report_without_resolve, u'report_without_resolve') | |
class JSTestsMixin: | |
def test_js(self): | |
[self.failUnless(test['result'], test['debug']) for test in self.js_test_details] | |
self.failUnless(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment