Moves concurrency tests back to scripts since they require prod setup
This commit is contained in:
parent
a7bab4a9a0
commit
98a9d890db
2 changed files with 34 additions and 29 deletions
34
scripts/concurrency_test.py
Normal file
34
scripts/concurrency_test.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import unittest
|
||||||
|
from multiprocessing.pool import Pool
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
urls = [f'http://localhost:{port}/api' for port in range(5921, 5925)]
|
||||||
|
comments = [self.make_comment(i) for i in range(1, 5)]
|
||||||
|
inputs = list(zip(urls, comments))
|
||||||
|
with Pool(4) as pool:
|
||||||
|
results = pool.map(self.send_comment_to_server, inputs)
|
||||||
|
results = list(filter(lambda x: 'comment_id' in x['result'], results))
|
||||||
|
self.assertIsNotNone(results)
|
||||||
|
self.assertEqual(len(results), len(inputs))
|
|
@ -232,32 +232,3 @@ class ListCommentsTest(unittest.TestCase):
|
||||||
self.assertIs(type(response['items']), list)
|
self.assertIs(type(response['items']), list)
|
||||||
self.assertEqual(response['total_items'], response_one['total_items'])
|
self.assertEqual(response['total_items'], response_one['total_items'])
|
||||||
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):
|
|
||||||
urls = [f'http://localhost:{port}/api' for port in range(5921, 5925)]
|
|
||||||
comments = [self.make_comment(i) for i in range(1, 5)]
|
|
||||||
inputs = list(zip(urls, comments))
|
|
||||||
with Pool(4) as pool:
|
|
||||||
results = pool.map(self.send_comment_to_server, inputs)
|
|
||||||
results = list(filter(lambda x: 'comment_id' in x['result'], results))
|
|
||||||
self.assertIsNotNone(results)
|
|
||||||
self.assertEqual(len(results), len(inputs))
|
|
||||||
|
|
Loading…
Reference in a new issue