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

De-duplicate Integration Testing and Tracker Client Code #767

Closed
Tracked by #669 ...
da2ce7 opened this issue Mar 29, 2024 · 3 comments
Closed
Tracked by #669 ...

De-duplicate Integration Testing and Tracker Client Code #767

da2ce7 opened this issue Mar 29, 2024 · 3 comments
Assignees
Labels
Code Cleanup / Refactoring Tidying and Making Neat

Comments

@da2ce7
Copy link
Contributor

da2ce7 commented Mar 29, 2024

part of:

src/shared/bit_torrent/tracker/http/client is mostly a copy-paste of the infrastructure code for: tests/servers/http/

De-duplicating this code would mean that our client code would be tested with our integration tests.

@da2ce7 da2ce7 self-assigned this Mar 29, 2024
@da2ce7 da2ce7 added the Code Cleanup / Refactoring Tidying and Making Neat label Mar 29, 2024
This was referenced Mar 29, 2024
@josecelano
Copy link
Member

josecelano commented Mar 29, 2024

Relates to: #622 (comment)

Hi @da2ce7 I wasn't sure if that is a good practice. I have the feeling we should move the client to another package and also primitives shared by the client and the server. However, I have to think deeply about it. The thing I don't like is tests could fail for two reasons: the client or the API endpoint.

ChatGPT

Moving your API client from test to production while maintaining reliability and ensuring comprehensive testing can indeed introduce some complexities. Your concerns about the potential for tests to fail due to issues with either the API itself or the client code are valid. Let’s explore the considerations and alternatives for managing this transition effectively.

Considerations for Using the Same API Client in Testing and Production

  1. Testing Isolation: One principle of testing is to isolate what you are testing. If you are testing the API, you ideally don’t want failures in the client code to affect the outcome of these tests. Similarly, when testing the client code, you want to isolate it from the API implementation.

  2. Code Reusability and Consistency: On the other hand, using the same code in testing and production can ensure that any bugs found in production are also catchable during testing. This consistency reduces the risk of discrepancies between how your production code behaves and how your test setup behaves.

  3. Reduced Duplication: By using the same client code in both testing and production environments, you reduce code duplication, which aligns with the DRY (Don't Repeat Yourself) principle. This can make maintenance easier but also requires careful management to ensure testing integrity.

Best Practices and Alternatives

  1. Mocking/Stubs for Client Testing: When testing the API client itself, consider using mocking or stubbing techniques to simulate API responses. This isolates the client code from the actual API, allowing you to test it under controlled conditions without relying on the availability or behavior of the API.

  2. Integration Tests with Real Requests: For integration tests that involve both the API and the client, using real requests can be beneficial to verify that the system works as expected in a real-world scenario. This can complement unit tests where components are tested in isolation.

  3. Separate Configuration for Testing and Production: Ensure that your API client can be configured differently for testing and production environments. This can include different base URLs, timeouts, and error handling strategies to better suit each context.

  4. Version Control and Feature Toggling: If introducing changes to the API client that might affect production, consider using version control branches or feature toggles. This allows you to test new changes in a controlled environment before rolling them out to production.

  5. Continuous Integration and Deployment (CI/CD) Pipelines: Utilize CI/CD pipelines to automate testing and ensure that changes to your API client are thoroughly tested at every stage of development before deployment.

  6. Canary Releases and Monitoring: When deploying changes to the API client in production, consider using canary releases to gradually roll out the change to a small subset of users first. Monitor the performance and error rates closely to catch any issues before a full rollout.

Conclusion

In essence, it's a common practice to use the same API client code in both testing and production to ensure consistency and reduce duplication. However, it's crucial to employ testing strategies that effectively isolate components under test, use mocking where appropriate, and carefully manage the transition of changes from development to production to maintain system reliability.

@josecelano josecelano changed the title De-deuplicate Intergration Testing and Tracker Client Code De-duplicate Integration Testing and Tracker Client Code Apr 17, 2024
@cgbosse
Copy link
Member

cgbosse commented May 24, 2024

@da2ce7
Jose is waiting for a reply on this issue.

@josecelano
Copy link
Member

Hi, we can close it. @da2ce7 feel free to re-open it. I think this is related to #689. Maybe the solution is to extract an independent package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Cleanup / Refactoring Tidying and Making Neat
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants