Skip to content

Conversation

@uruwhy
Copy link
Contributor

@uruwhy uruwhy commented Oct 30, 2025

Description

  • properly close FTP and TCP contacts to address associated warnings in unit tests
  • make FTP unit tests able to remove non-empty FTP directory, and use test directory name (fixes edge case where FTP unit test fails when users have previously used the FTP contact)
  • set the pyasn1 version to 0.5.x to address pyasn1-related warnings in unit tests
  • remove event_loop fixtures in unit tests to address related warnings
  • update mock return setup in data svc test to address warnings

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Ran unit tests locally
Ran manx agent with TCP contact to verify functionality still intact, verified server closed with dead and live manx sessions
Ran sandcat agent with FTP contact to verify functionality still intact

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@uruwhy uruwhy marked this pull request as ready for review December 9, 2025 14:29
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 9, 2025

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses various unit test warnings by improving resource cleanup, updating test fixtures, and pinning dependency versions.

  • Properly implements cleanup logic for TCP and FTP contacts to prevent resource warnings
  • Updates mock setup for async methods and removes deprecated event_loop fixture usage
  • Improves FTP test robustness with better directory handling

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/contacts/contact_tcp.py Adds proper cleanup methods with task cancellation and session closure handling for TCP contact server
app/contacts/contact_ftp.py Simplifies FTP server startup by removing Python version-specific code paths and adds stop method
tests/contacts/test_contact_ftp.py Uses test-specific directory name and shutil.rmtree for non-empty directory cleanup
tests/services/test_data_svc.py Updates async mock setup to use return_value=None instead of async_mock_return helper
tests/conftest.py Removes deprecated event_loop fixture parameter from async fixtures
tests/api/v2/test_knowledge.py Removes deprecated event_loop fixture parameter from async fixture
requirements.txt Pins pyasn1 to version 0.5.x to address related warnings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

self.op_loop_task.cancel()
if self.server_task:
self.server_task.cancel()
_ = await asyncio.gather(self.server_task, self.op_loop_task, return_exceptions=True)
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asyncio.gather() call will fail with a TypeError if either self.server_task or self.op_loop_task is None. This can occur if stop() is called before start() has been invoked. Consider filtering out None values before passing them to gather(), or checking that both tasks are not None before calling gather().

Suggested change
_ = await asyncio.gather(self.server_task, self.op_loop_task, return_exceptions=True)
tasks = [t for t in (self.server_task, self.op_loop_task) if t is not None]
if tasks:
_ = await asyncio.gather(*tasks, return_exceptions=True)

Copilot uses AI. Check for mistakes.

async def stop(self):
self.task.cancel()
await self.server.close()
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stop() method will fail with an AttributeError if called when self.server is None. This can occur if stop() is called before start() has been invoked. Consider adding a check to ensure self.server is not None before calling close().

Suggested change
await self.server.close()
if self.server is not None:
await self.server.close()
self.server = None

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants