-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrote first api performance tests #2218
Wrote first api performance tests #2218
Conversation
@pytest.mark.deployment_community | ||
def test_api_performance(ansible_config): | ||
|
||
|
||
config = ansible_config("admin") | ||
api_client = get_client( | ||
config=config, | ||
request_token=False, | ||
require_auth=False | ||
) | ||
|
||
threshold = 0.25 | ||
|
||
resp = api_client('http://localhost:5001/api/_ui/v1/settings/', method='GET') | ||
print("Thhhhhhhe response is") | ||
print (resp) | ||
|
||
results = [] | ||
|
||
for url, baseline in URLS.items(): | ||
|
||
start_time = time.time() | ||
resp = api_client('http://localhost:5001' + url, method='GET') | ||
elapsed_time = time.time() - start_time | ||
|
||
difference = (elapsed_time - baseline) / baseline | ||
if difference > threshold: | ||
results.append(f"{url} exceeds threshold with {difference}") | ||
else: | ||
results.append(f"{url} does not exceed threshold and its difference is {difference}") | ||
|
||
print("httttttttttttthe result is") | ||
print(results) | ||
|
||
assert True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use a local fixture for the client, this way other tests could use the same.
Also it looks like a good idea to use parameterized test so each URL is tested individually and we can see each one as a result in the tests
@pytest.fixture(scope="function")
def api_client(ansible_config):
config = ansible_config("admin")
api_client = get_client(
config=config,
request_token=False,
require_auth=False
)
return api_client
@pytest.mark.deployment_community
@pytest.mark.parametrize("url,baseline", URLS.items())
def test_api_performance(api_client, url, baseline):
threshold = 0.25
results = []
start_time = time.time()
resp = api_client('http://localhost:5001' + url, method='GET')
elapsed_time = time.time() - start_time
difference = (elapsed_time - baseline) / baseline
assert difference < threshold
URLS = { | ||
'/api/_ui/v1/settings/' : 0.5, | ||
'/api/ui/v1/namespaces/' : 0.5, | ||
'/api/_ui/v1/auth/login/' : 0.5, | ||
'/api/_ui/v1/collection-versions/' : 0.5, | ||
'/api/_ui/v1/distributions/' : 0.5, | ||
'/api/_ui/v1/imports/collections/' : 0.5, | ||
'/api/_ui/v1/landing-page/': 0.5, | ||
'/api/_ui/v1/me/' : 0.5, | ||
'/api/_ui/v1/remotes/' : 0.5, | ||
'/api/_ui/v1/search/' : 0.5, | ||
'/api/_ui/v1/settings/' : 0.5, | ||
'/api/_ui/v1/synclists/': 0.5, | ||
'/api/_ui/v1/users/': 0.5, | ||
'/api/_ui/v1/tags/roles/': 0.5, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this object could get more nesting data, so we can play with different methods.
URLS = {
'/api/_ui/v1/settings/': {
'baseline': 0.5,
'method': 'GET'
},
'/api/other_url': {
'baseline': 0.7,
'method': 'POST',
'payload': {...}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I will integrate your advice.
No Issue
No Issue Signed-off-by: Stevenson Michel <[email protected]>
No Issue
No Issue
No Issue Signed-off-by: Stevenson Michel <[email protected]>
No Issue
No Issue
What is this PR doing:
Issue: AAH-####
Reviewers must know:
PR Author & Reviewers: Keep or remove backport labels per Backporting Guidelines
Reviewers: Look for sound code, no code smells, docs & test coverage
Merger: When merging, include the Jira issue link in the squashed commit