Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
fix benchmark example
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Aug 19, 2015
1 parent 18ae59a commit abcf9ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions examples/benchmark/thrift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# THE SOFTWARE.

import os
import sys
import threading

from tornado import gen, ioloop
Expand All @@ -43,6 +44,7 @@

def report_work():
print local.requests
sys.stdout.flush()
local.requests = 0


Expand Down
14 changes: 7 additions & 7 deletions examples/benchmark/thrift/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
values = {'hello': 'world'}


@app.register(KeyValue)
def getValue(request, response):
key = request.args.key
@app.thrift.register(KeyValue)
def getValue(request):
key = request.body.key
value = values.get(key)

if value is None:
Expand All @@ -44,10 +44,10 @@ def getValue(request, response):
return value


@app.register(KeyValue)
def setValue(request, response):
key = request.args.key
value = request.args.value
@app.thrift.register(KeyValue)
def setValue(request):
key = request.body.key
value = request.body.value
values[key] = value


Expand Down
18 changes: 11 additions & 7 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def popen(path, wait_for_listen=False):
('raw', 'simple/raw/'),
('json', 'simple/json/'),
('thrift', 'simple/thrift/'),
('bench', 'benchmark/thrift/'),
('guide', 'guide/keyvalue/keyvalue/'),
)
)
Expand All @@ -75,18 +76,14 @@ def test_example(scheme, path):
with popen(server_path, wait_for_listen=True):
with popen(client_path) as client:

out = client.stdout.read()
body = client.stdout.readline().strip()
headers = client.stdout.readline().strip()

# TODO the guide test should be the same as others
if scheme == 'guide':
assert out == 'Hello, world!\n'
assert body == 'Hello, world!'
return

try:
body, headers = out.split(os.linesep)[:-1]
except ValueError:
raise AssertionError(out + client.stderr.read())

if scheme == 'raw':

assert body == 'resp body'
Expand All @@ -104,6 +101,10 @@ def test_example(scheme, path):
'resp': 'header'
}

elif scheme == 'bench':
assert int(body)
assert int(headers)

elif scheme == 'thrift':

headers = json.loads(headers)
Expand All @@ -112,3 +113,6 @@ def test_example(scheme, path):
assert headers == {
'resp': 'header',
}

else:
assert False

0 comments on commit abcf9ad

Please sign in to comment.