Skip to content

Commit

Permalink
fix tornado 4 test compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyOT committed Jul 18, 2014
1 parent 033ee85 commit ed9cfba
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
6 changes: 3 additions & 3 deletions docs/source/conf.py
Expand Up @@ -41,16 +41,16 @@

# General information about the project.
project = u'Toto'
copyright = u'2013, Jeremy Olmsted-Thompson'
copyright = u'2014, Jeremy Olmsted-Thompson'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.12.6'
version = '0.12.8'
# The full version, including alpha/beta/rc tags.
release = '0.12.6'
release = '0.12.8'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -21,8 +21,8 @@
platforms=['OS X', 'Linux'],
url='http://toto.li',
packages=['toto','toto.methods','toto.methods.account'],
requires=['tornado(>=3.2, <4.0)',],
install_requires=['tornado==3.2.2',],
requires=['tornado(>=3.2)',],
install_requires=['tornado>=3.2',],
provides=['toto',],
scripts=['scripts/toto-create',],
description='A Tornado based framework designed to accelerate web service development',
Expand Down
10 changes: 10 additions & 0 deletions tests/test_server.py
Expand Up @@ -8,6 +8,16 @@
from multiprocessing import Process, active_children
from toto.server import TotoServer
from time import sleep, time
from toto.handler import TotoHandler
import logging

def before_handler(handler, transaction, method):
logging.info('Begin %s %s' % (method, transaction))

def after_handler(handler, transaction):
logging.info('Finished %s' % transaction)
TotoHandler.set_before_handler(before_handler)
TotoHandler.set_after_handler(after_handler)

def run_server(processes=1, daemon='start'):
TotoServer(method_module='web_methods', port=9000, debug=True, processes=processes, daemon=daemon, pidfile='server.pid').run()
Expand Down
29 changes: 24 additions & 5 deletions tests/test_worker.py
Expand Up @@ -8,8 +8,23 @@
from multiprocessing import Process, active_children
from toto.worker import TotoWorkerService
from toto.workerconnection import WorkerConnection
from tornado.gen import engine
from tornado.gen import coroutine
from tornado.concurrent import Future
from tornado.ioloop import IOLoop
from time import sleep, time
from threading import Thread

def run_loop(func):
def wrapper():
ioloop = IOLoop()
@coroutine
def looped():
yield func()
ioloop.stop()
ioloop.add_callback(looped)
thread = Thread(target=ioloop.start)
thread.start()
return wrapper

def run_server(port, daemon='start'):
TotoWorkerService(method_module='worker_methods', worker_bind_address='tcp://*:%d' % port, worker_socket_address='ipc:///tmp/workerservice%d.sock' % port, control_socket_address='ipc:///tmp/workercontrol%d.sock', debug=True, daemon=daemon, pidfile='worker-%d.pid' % port).run()
Expand Down Expand Up @@ -54,7 +69,8 @@ def cb(response):
def test_method_generator(self):
resp = []
parameters = {'arg1': 1, 'arg2': 'hello'}
@engine
@run_loop
@coroutine
def run():
resp.append((yield self.worker.invoke('return_value', parameters, await=True)))
run()
Expand All @@ -75,7 +91,8 @@ def cb(response):
def test_method_alt_invocation_generator(self):
resp = []
parameters = {'arg1': 1, 'arg2': 'hello'}
@engine
@run_loop
@coroutine
def run():
resp.append((yield self.worker.return_value(parameters, await=True)))
run()
Expand Down Expand Up @@ -108,7 +125,8 @@ def cb(response):
def test_exception_generator(self):
resp = []
parameters = {'arg1': 1, 'arg2': 'hello'}
@engine
@run_loop
@coroutine
def run():
resp.append((yield self.worker.invoke('throw_exception', parameters, await=True)))
run()
Expand All @@ -130,7 +148,8 @@ def cb(response):

def test_toto_exception_generator(self):
resp = []
@engine
@run_loop
@coroutine
def run():
parameters = {'arg1': 1, 'arg2': 'hello'}
resp.append((yield self.worker.invoke('throw_toto_exception', parameters, await=True)))
Expand Down
28 changes: 14 additions & 14 deletions toto/handler.py
Expand Up @@ -433,18 +433,18 @@ def _before_invoke(self, transaction_id, method):
def _after_invoke(self, transaction_id):
pass

@classmethod
def set_before_handler(cls, handler):
'''Set the handler that will be called before any method invocation. This is useful for instrumentation. The handler will be
called with ``handler, transaction_id, method``, where ``transaction_id`` is a UUID and ``method`` is the name of the
invoked method. For batch requests each invocation will be tracked and logged separately, but there will also be a message
logged with name ``"<batch>"`` which wraps the entire request. The default handler is a no op.
'''
cls._before_invoke = handler
@classmethod
def set_before_handler(cls, handler):
'''Set the handler that will be called before any method invocation. This is useful for instrumentation. The handler will be
called with ``handler, transaction_id, method``, where ``transaction_id`` is a UUID and ``method`` is the name of the
invoked method. For batch requests each invocation will be tracked and logged separately, but there will also be a message
logged with name ``"<batch>"`` which wraps the entire request. The default handler is a no op.
'''
cls._before_invoke = handler

@classmethod
def set_after_handler(cls, handler):
'''Set the handler that will be called after any method invocation. The handler will be called with ``handler, transaction_id``,
where ``transaction_id`` is the UUID that was passed to the before handler. The default handler is a no op.
'''
cls._after_invoke = handler
@classmethod
def set_after_handler(cls, handler):
'''Set the handler that will be called after any method invocation. The handler will be called with ``handler, transaction_id``,
where ``transaction_id`` is the UUID that was passed to the before handler. The default handler is a no op.
'''
cls._after_invoke = handler

0 comments on commit ed9cfba

Please sign in to comment.