示例#1
0
 def tearDown(self):
     self.http_server.stop()
     self.io_loop.run_sync(self.http_server.close_all_connections,
                           timeout=get_async_test_timeout())
     if (not IOLoop.initialized() or
             self.http_client.io_loop is not IOLoop.instance()):
         self.http_client.close()
     super(AsyncHTTPTestCase, self).tearDown()
示例#2
0
def run_tests():
    url = options.url + '/getCaseCount'
    control_ws = yield websocket_connect(url, None)
    num_tests = int((yield control_ws.read_message()))
    logging.info('running %d cases', num_tests)
    msg = yield control_ws.read_message()
    assert msg is None

    for i in range(1, num_tests + 1):
        logging.info('running test case %d', i)
        url = options.url + '/runCase?case=%d&agent=%s' % (i, options.name)
        test_ws = yield websocket_connect(url, None, compression_options={})
        while True:
            message = yield test_ws.read_message()
            if message is None:
                break
            test_ws.write_message(message, binary=isinstance(message, bytes))

    url = options.url + '/updateReports?agent=%s' % options.name
    update_ws = yield websocket_connect(url, None)
    msg = yield update_ws.read_message()
    assert msg is None
    IOLoop.instance().stop()
示例#3
0
 def tearDown(self):
     # Clean up Subprocess, so it can be used again with a new ioloop.
     Subprocess.uninitialize()
     self.io_loop.clear_current()
     if (not IOLoop.initialized() or
             self.io_loop is not IOLoop.instance()):
         # Try to clean up any file descriptors left open in the ioloop.
         # This avoids leaks, especially when tests are run repeatedly
         # in the same process with autoreload (because curl does not
         # set FD_CLOEXEC on its file descriptors)
         self.io_loop.close(all_fds=True)
     super(AsyncTestCase, self).tearDown()
     # In case an exception escaped or the StackContext caught an exception
     # when there wasn't a wait() to re-raise it, do so here.
     # This is our last chance to raise an exception in a way that the
     # unittest machinery understands.
     self.__rethrow()
示例#4
0
    if not args:
        args = ['localhost', 'www.google.com',
                'www.facebook.com', 'www.dropbox.com']

    resolvers = [Resolver(), ThreadedResolver()]

    if twisted is not None:
        from censiotornado.platform.twisted import TwistedResolver
        resolvers.append(TwistedResolver())

    if pycares is not None:
        from censiotornado.platform.caresresolver import CaresResolver
        resolvers.append(CaresResolver())

    family = {
        'unspec': socket.AF_UNSPEC,
        'inet': socket.AF_INET,
        'inet6': socket.AF_INET6,
        }[options.family]

    for host in args:
        print('Resolving %s' % host)
        for resolver in resolvers:
            addrinfo = yield resolver.resolve(host, 80, family)
            print('%s: %s' % (resolver.__class__.__name__,
                              pprint.pformat(addrinfo)))
        print()

if __name__ == '__main__':
    IOLoop.instance().run_sync(main)
示例#5
0
#!/usr/bin/env python

from censiotornado.ioloop import IOLoop
from censiotornado.options import define, options, parse_command_line
from censiotornado.websocket import WebSocketHandler
from censiotornado.web import Application

define('port', default=9000)


class EchoHandler(WebSocketHandler):
    def on_message(self, message):
        self.write_message(message, binary=isinstance(message, bytes))

    def get_compression_options(self):
        return {}


if __name__ == '__main__':
    parse_command_line()
    app = Application([
        ('/', EchoHandler),
    ])
    app.listen(options.port, address='127.0.0.1')
    IOLoop.instance().start()
示例#6
0
def main():
    parse_command_line()

    IOLoop.instance().add_callback(run_tests)

    IOLoop.instance().start()