Skip to content
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

Fix logic for xfail test in api performance test #4657

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
- Added tests for checking agent status upon ungraceful closure.([#4146](https:/wazuh/wazuh-qa/pull/4146)) \- (Tests)
- Agent syncronization testing after group deleting ([#4143](https:/wazuh/wazuh-qa/pull/4143)) \- (Tests)
- Add test for AWS Custom Logs. ([#4675](https:/wazuh/wazuh-qa/pull/4675)) \- (Tests)
- Add new behaviour for endpoints marked as xfail in api_endpoints_performance test ([#4657](https:/wazuh/wazuh-qa/pull/4657)) \ (Tests)

### Changed

Expand Down
28 changes: 21 additions & 7 deletions tests/performance/test_api/test_api_endpoints_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from os.path import join, dirname, realpath
from time import sleep

import warnings
import pytest
import requests
from yaml import safe_load
Expand All @@ -18,7 +19,7 @@
'method': 'put'},
'/agents/group': {'message': 'Investigate performance issues with PUT /agents/group API endpoint: '
'https:/wazuh/wazuh/issues/13872',
'method': 'put'}
'method': 'put'},
}


Expand All @@ -32,21 +33,32 @@ def test_api_endpoints(test_case, set_api_test_environment, api_healthcheck):
set_api_test_environment (fixture): Fixture that modifies the API security options.
api_healthcheck (fixture): Fixture used to check that the API is ready to respond requests.
"""
# Apply xfails
if test_case['endpoint'] in xfailed_items.keys() and \
test_case['method'] == xfailed_items[test_case['endpoint']]['method']:
pytest.xfail(xfailed_items[test_case['endpoint']]['message'])

base_url = api_details['base_url']
headers = api_details['auth_headers']
response = None

try:
response = getattr(requests, test_case['method'])(f"{base_url}{test_case['endpoint']}", headers=headers,
params=test_case['parameters'], json=test_case['body'],
verify=False)
assert response.status_code == 200
assert response.json()['error'] == 0

except AssertionError as e:
# If the assertion fails, and is marked as xfail
if test_case['endpoint'] in xfailed_items.keys() and \
test_case['method'] == xfailed_items[test_case['endpoint']]['method']:
pytest.xfail(xfailed_items[test_case['endpoint']]['message'])

raise e

else:
# If the test does not fail and is marked as xfail, issue a warning
if test_case['endpoint'] in xfailed_items.keys() and \
test_case['method'] == xfailed_items[test_case['endpoint']]['method']:
warnings.warn(f"Test {test_case['endpoint']} should have failed due "
f"to {xfailed_items[test_case['endpoint']]['message']}")

finally:
# Add useful information to report as stdout
try:
Expand All @@ -56,4 +68,6 @@ def test_api_endpoints(test_case, set_api_test_environment, api_healthcheck):
except KeyError:
print('No response available')

test_case['method'] == 'put' and test_case['restart'] and sleep(restart_delay)
# Restart logic as before
if test_case['method'] == 'put' and test_case['restart']:
sleep(restart_delay)
Loading