From 1332610b571c1955184a38c3bc1f05fc3cad5337 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Wed, 24 Jul 2019 01:47:14 -0400 Subject: [PATCH] Adds testing for the database handling concurrent write requests --- tests/concurrent_write_test.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/concurrent_write_test.py diff --git a/tests/concurrent_write_test.py b/tests/concurrent_write_test.py new file mode 100644 index 0000000..ef631ab --- /dev/null +++ b/tests/concurrent_write_test.py @@ -0,0 +1,29 @@ +from multiprocessing import Pool +import json +import requests + + +def make_comment(num): + return{ + 'jsonrpc': '2.0', + 'id': None, + 'method': 'create_comment', + 'params': { + 'comment': f'Comment #{num}', + 'claim_id': '6d266af6c25c80fa2ac6cc7662921ad2e90a07e7', + } + } + + +def send_comment_to_server(params): + with requests.post(params[0], json=params[1]) as req: + return req.json() + + +if __name__ == '__main__': + urls = [f'http://localhost:{port}/api' for port in range(5921, 5925)] + comments = [make_comment(i) for i in range(1, 5)] + inputs = list(zip(urls, comments)) + print(json.dumps(inputs, indent=2)) + with Pool(4) as pool: + print(json.dumps(pool.map(send_comment_to_server, inputs), indent=2))