def test_concurrent():
    req1 = make_request('heavy_request', [1])
    req2 = make_request('heavy_request', [1])
    req3 = make_request('heavy_request', [1])

    start = time()
    rpc_result = app.dispatch([req1, req2, req3])
    time_took = time() - start

    assert rpc_result[0].get('result') == 'home page!', rpc_result
    assert time_took < 1.5, time_took
def test_make_request_named_arg():
    created_request = make_request('test_created', {'x': 1, 'y': 2})
    assert created_request['jsonrpc'] == '2.0'
    assert created_request['method'] == 'test_created'
    assert created_request['params'] == {'x': 1, 'y': 2}
def test_make_request_positional_arg():
    created_request = make_request('test_created_positional', ['first', 'second', 'third'])
    assert created_request['jsonrpc'] == '2.0'
    assert created_request['method'] == 'test_created_positional'
    assert created_request['params'] == ['first', 'second', 'third']
Exemple #4
0
if __name__ == '__main__':
    # you can call functions simply
    print(aa(aa='cc'))
    # => 'cc called'

    # you can call function via json rpc protocol
    rpc = rpc_dispatcher({
        'jsonrpc': '2.0',
        'method': 'aa',
        'params': {
            'aa': 'rpc'
        },
        'id': 111,
    })
    rpc2 = rpc_dispatcher(make_request('test/hyoe', {'x': 20, 'y': 10}))
    print(json.dumps(rpc))
    # => {"jsonrpc": "2.0", "result": "cccc  called", "id": "111"}
    print(json.dumps(rpc))

    # => u'{"jsonrpc": "2.0", "result": "cccc  called", "id": "some_uuid_for_you"}'

    # there is HTTP server to receive rpc call
    def make_app():
        return tornado.web.Application([
            (r'/rpc', create_handler(tornado.web.RequestHandler)),
        ])

    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()