Makes concurrency test into server_test
This commit is contained in:
parent
697b88e0d9
commit
e14c94121b
3 changed files with 43 additions and 57 deletions
|
@ -1,10 +0,0 @@
|
||||||
Faker>=1.0.7
|
|
||||||
asyncio>=3.4.3
|
|
||||||
aiohttp==3.5.4
|
|
||||||
aiojobs==0.2.2
|
|
||||||
ecdsa==0.13
|
|
||||||
cryptography==2.5
|
|
||||||
aiosqlite==0.10.0
|
|
||||||
PyNaCl>=1.3.0
|
|
||||||
requests
|
|
||||||
cython
|
|
|
@ -1,29 +0,0 @@
|
||||||
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))
|
|
|
@ -1,4 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
from multiprocessing.pool import Pool
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
from itertools import *
|
from itertools import *
|
||||||
|
@ -34,6 +36,22 @@ def nothing():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
replace = {
|
||||||
|
'claim_id': fake.sha1,
|
||||||
|
'comment': fake.text,
|
||||||
|
'channel_id': fake.sha1,
|
||||||
|
'channel_name': fake_lbryusername,
|
||||||
|
'signature': fake.uuid4,
|
||||||
|
'parent_id': fake.sha256
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def create_test_comments(values: iter, **default):
|
||||||
|
vars_combo = chain.from_iterable(combinations(values, r) for r in range(1, len(values) + 1))
|
||||||
|
return [{k: replace[k]() if k in comb else v for k, v in default.items()}
|
||||||
|
for comb in vars_combo]
|
||||||
|
|
||||||
|
|
||||||
class ServerTest(unittest.TestCase):
|
class ServerTest(unittest.TestCase):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -216,23 +234,30 @@ class ListCommentsTest(unittest.TestCase):
|
||||||
self.assertEqual(response['total_pages'], response_one['total_pages'])
|
self.assertEqual(response['total_pages'], response_one['total_pages'])
|
||||||
|
|
||||||
|
|
||||||
|
class ConcurrentWriteTest(unittest.TestCase):
|
||||||
|
@staticmethod
|
||||||
|
def make_comment(num):
|
||||||
|
return {
|
||||||
|
'jsonrpc': '2.0',
|
||||||
|
'id': num,
|
||||||
|
'method': 'create_comment',
|
||||||
|
'params': {
|
||||||
|
'comment': f'Comment #{num}',
|
||||||
|
'claim_id': '6d266af6c25c80fa2ac6cc7662921ad2e90a07e7',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def send_comment_to_server(params):
|
||||||
|
with requests.post(params[0], json=params[1]) as req:
|
||||||
|
return req.json()
|
||||||
|
|
||||||
|
def test01Concurrency(self):
|
||||||
replace = {
|
urls = [f'http://localhost:{port}/api' for port in range(5921, 5925)]
|
||||||
'claim_id': fake.sha1,
|
comments = [self.make_comment(i) for i in range(1, 5)]
|
||||||
'comment': fake.text,
|
inputs = list(zip(urls, comments))
|
||||||
'channel_id': fake.sha1,
|
with Pool(4) as pool:
|
||||||
'channel_name': fake_lbryusername,
|
results = pool.map(self.send_comment_to_server, inputs)
|
||||||
'signature': fake.uuid4,
|
results = list(filter(lambda x: 'comment_id' in x['result'], results))
|
||||||
'parent_id': fake.sha256
|
self.assertIsNotNone(results)
|
||||||
}
|
self.assertEqual(len(results), len(inputs))
|
||||||
|
|
||||||
|
|
||||||
def create_test_comments(values: iter, **default):
|
|
||||||
vars_combo = chain.from_iterable(combinations(values, r) for r in range(1, len(values) + 1))
|
|
||||||
return [{k: replace[k]() if k in comb else v for k, v in default.items()}
|
|
||||||
for comb in vars_combo]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue