-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 - Broken tests #3013
base: master
Are you sure you want to change the base?
Fix - Broken tests #3013
Conversation
I could fix all test failures locally (macOS), but it still remains tons of warnings (see CI/CD).
Now, the CI/CD still does not succeed: It looks like the What do you think @elegantmoose and @clenk? |
I tried to understand the remaining event loop warnings that appear when running tests, the ones that produce Task was destroyed but it is pending! or RuntimeError: Event loop is closed. I focused on a single test that cause such warnings. pytest --asyncio-mode=auto --tb=short tests/services/test_app_svc.py::TestAppService::test_mark_agent_as_untrusted_running_operation After investigating, I figured out that the "destroyed" asyncio tasks come from the application itself. That means when the test method start, It is already "too late" as the event loop has already a set of pending tasks. @bleepbop and @christophert, you both have worked on the tests. I could reduce (but not completely suppress) the amount of warning by just applying this function at the beginning or the end of the test (whatever): async def cancel_pending_tasks():
loop = asyncio.get_running_loop()
current_task = asyncio.current_task(loop)
pending_tasks = [task for task in asyncio.all_tasks(loop) if task is not current_task and not task.done()]
for task in pending_tasks:
task.cancel() However, this is not a clean way to fix that specific issue. |
c8d948b
to
44203bd
Compare
Thanks for the great work! I was working on some new features myself and ran into a lot of failing tests - wondering where they came from. Then I noticed they fail on the main branch as well. I just pulled your branch and the tests are fixed. In my opinion, adding |
While rebasing the work on the new |
@jbaptperez back on this, sorry for delay |
app/api/rest_api.py
Outdated
@@ -43,7 +43,7 @@ async def enable(self): | |||
self.app_svc.application.router.add_route('*', '/api/rest', self.rest_core) | |||
self.app_svc.application.router.add_route('GET', '/api/{index}', self.rest_core_info) | |||
self.app_svc.application.router.add_route('GET', '/file/download_exfil', self.download_exfil_file) | |||
self.app_svc.application.router.add_route('GET', '/{tail:(?!plugin/).*}', self.handle_catch) | |||
self.app_svc.application.router.add_route('GET', '/{tail:(?!plugin|api/v2/).*}', self.handle_catch) |
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.
self.app_svc.application.router.add_route('GET', '/{tail:(?!plugin|api/v2/).*}', self.handle_catch) | |
self.app_svc.application.router.add_route('GET', '/{tail:(?!plugins/|api/v2/).*}', self.handle_catch) |
To maintain the previous path condition (also, it should be plugins/
rather than the original plugin/
value since the plugin paths use plugins/
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.
Thanks.
I fixed up the original commit with the plugin
to plugin/
change.
However, I put the plugin/
to plugins/
into a dedicated commit.
I saw a lot of /plugin/...
endpoints (global RegEx search: add_route.+plugin/
).
Are you sure the change that adds an s
is correct?
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.
No, good catch. I was going off the URLs in my browser when clicking different plugins, but the ones in add_route
don't have the s
as you pointed out. We'll just do plugin/
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.
OK. I removed the commit and rebased my branch on the new master
.
02af67f
to
19f568d
Compare
data_svc_handle = BaseService.get_service('data_svc') | ||
seeded_facts = [] | ||
if self.source: | ||
seeded_facts = await data_svc_handle.get_facts_from_source(self.source.id) | ||
seeded_facts = await knowledge_svc_handle.get_facts(criteria=dict(source=self.source.id)) |
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.
It sounds like these changes from #2978 were causing issues in your tests - I'd like to avoid undoing changes from previous PRs and fix the corresponding tests if possible.
@elegantmoose @clenk thoughts?
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.
Correct, the changes broke the tests.
However, after passing a couple of hours trying to understand what was going on (using a debugger, etc.), I figured out that related data structure were not so similar and maybe the shortcut of #2978 cannot really be applied this way.
I don't master the code so here, I clearly need help to have a proper fix.
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.
I see. Let me talk with some folks to see how we want to approach this. Will get back to you shortly
Updates the pytest command to include the asyncio mode (required).
Jinja templates where not initialized in the test server.
A catch-all route was set in RestApi class before adding API v2 routes.
Method TestHealthApi.test_get_health. The new "access" field was not taken into account.
Method TestHealthApi.test_unauthorized_get_health. Empty access table was not taken into account.
Method TestPayloadsApi.test_get_payloads. Adds missing payloads routes. Updates the test to retrieve payloads (real temporary files).
Function test_access_denied. Deleted because there is no GET "/enter" endpoint. A catch-all route redirects "/enter" to "/".
Function test_custom_rejecting_login_handler. Using an endpoint that requires an authentication to check the redirection to the login page ("/").
Function test_home (only in CI/CD). The "index.html" template was missing in "plugins/magma/dist". Adds Node.js 20 (active LTS) dependency to the CI/CD. Adds "npm install" and "npm run build" commands to the "Install dependencies" step.
This reverts commit 3ad8849. The reverted commit broke tests/objects/test_link.py tests.
Makes it require authenticated users. Simplifies back the management of the returned "access" field.
19f568d
to
1d3ccc3
Compare
Description
Fixes:
CONTRIBUTONG.md
according to new aiohttp requirements in the CLI)Type of change
Please delete options that are not relevant.
How Has This Been Tested?
All tests:
Checklist: