-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add e2e performance test * remove error import * change request num * change request num * change by review * fix review * remove unsed value * fix review
- Loading branch information
1 parent
e4afff7
commit c10a638
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from lyrebird import event | ||
import time | ||
|
||
TITLE = 'test_encoder_decoder' | ||
CHECKER_TIME = 0.5 | ||
|
||
@event('flow') | ||
def test_checker(flow): | ||
time.sleep(CHECKER_TIME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
import requests | ||
from concurrent.futures import ThreadPoolExecutor, as_completed | ||
import time | ||
|
||
|
||
|
||
current_path = os.path.abspath(os.path.dirname(__file__)) | ||
checker_path = f'{current_path}/assets/checker.py' | ||
modifier_path = f'{current_path}/assets/flow_editor.py' | ||
REQUEST_NUM = 60 | ||
AVU_DURATION = 2 | ||
ALL_DURATION = 15 | ||
|
||
|
||
def fetch_url(req_url): | ||
response = requests.get(req_url) | ||
return response.text | ||
|
||
|
||
def send_request(url): | ||
with ThreadPoolExecutor() as executor: | ||
futures = [executor.submit(fetch_url, url) for i in range(REQUEST_NUM)] | ||
for future in as_completed(futures): | ||
try: | ||
res = future.result() | ||
except Exception as e: | ||
print(f"Request Error:{e}") | ||
|
||
|
||
def test_performance(lyrebird, mock_server): | ||
start_time = time.time() | ||
send_request(lyrebird.uri_mock + mock_server.api_long_time_service) | ||
end_time = time.time() | ||
duration = end_time - start_time | ||
r = requests.get(url=lyrebird.api_flows).json() | ||
sum_time = sum(flow['duration'] for flow in r) | ||
assert len(r) == REQUEST_NUM | ||
assert sum_time/len(r) < AVU_DURATION | ||
assert duration < ALL_DURATION | ||
lyrebird.stop() | ||
|
||
|
||
def test_performance_with_checker(lyrebird_with_args, mock_server): | ||
lyrebird_with_args.start(checker_path=[checker_path]) | ||
start_time = time.time() | ||
send_request(lyrebird_with_args.uri_mock + mock_server.api_long_time_service) | ||
end_time = time.time() | ||
duration = end_time - start_time | ||
r = requests.get(url=lyrebird_with_args.api_flows).json() | ||
sum_time = sum(flow['duration'] for flow in r) | ||
assert len(r) == REQUEST_NUM | ||
assert sum_time/len(r) < AVU_DURATION | ||
assert duration < ALL_DURATION | ||
lyrebird_with_args.stop() | ||
|
||
|
||
def test_performance_with_modifier(lyrebird_with_args, mock_server): | ||
lyrebird_with_args.start(checker_path=[modifier_path]) | ||
start_time = time.time() | ||
send_request(lyrebird_with_args.uri_mock + mock_server.api_long_time_service) | ||
end_time = time.time() | ||
duration = end_time - start_time | ||
r = requests.get(url=lyrebird_with_args.api_flows).json() | ||
sum_time = sum(flow['duration'] for flow in r) | ||
assert len(r) == REQUEST_NUM | ||
assert sum_time/len(r) < AVU_DURATION | ||
assert duration < ALL_DURATION | ||
lyrebird_with_args.stop() | ||
|
||
|
||
def test_performance_with_checker_and_modifier(lyrebird_with_args, mock_server): | ||
lyrebird_with_args.start(checker_path=[checker_path, modifier_path]) | ||
start_time = time.time() | ||
send_request(lyrebird_with_args.uri_mock + mock_server.api_long_time_service) | ||
end_time = time.time() | ||
duration = end_time - start_time | ||
r = requests.get(url=lyrebird_with_args.api_flows).json() | ||
sum_time = sum(flow['duration'] for flow in r) | ||
assert len(r) == REQUEST_NUM | ||
assert sum_time/len(r) < AVU_DURATION | ||
assert duration < ALL_DURATION | ||
lyrebird_with_args.stop() |