diff --git a/CHANGELOG.md b/CHANGELOG.md index d7933252a8..a274353163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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://github.com/wazuh/wazuh-qa/pull/4146)) \- (Tests) - Agent syncronization testing after group deleting ([#4143](https://github.com/wazuh/wazuh-qa/pull/4143)) \- (Tests) - Add test for AWS Custom Logs. ([#4675](https://github.com/wazuh/wazuh-qa/pull/4675)) \- (Tests) +- Add new behaviour for endpoints marked as xfail in api_endpoints_performance test ([#4657](https://github.com/wazuh/wazuh-qa/pull/4657)) \ (Tests) ### Changed diff --git a/tests/performance/test_api/test_api_endpoints_performance.py b/tests/performance/test_api/test_api_endpoints_performance.py index eef8a84c16..b74d01dda4 100755 --- a/tests/performance/test_api/test_api_endpoints_performance.py +++ b/tests/performance/test_api/test_api_endpoints_performance.py @@ -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 @@ -18,7 +19,7 @@ 'method': 'put'}, '/agents/group': {'message': 'Investigate performance issues with PUT /agents/group API endpoint: ' 'https://github.com/wazuh/wazuh/issues/13872', - 'method': 'put'} + 'method': 'put'}, } @@ -32,14 +33,10 @@ 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'], @@ -47,6 +44,21 @@ def test_api_endpoints(test_case, set_api_test_environment, api_healthcheck): 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: @@ -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)