Skip to content

Conversation

@thiyaguk09
Copy link
Owner

Description

This PR resolves intermittent flakiness and timeouts in the Service system tests within common.ts.

Key Changes:

  • Dynamic Ports: Refactored mock servers to use port 0 (ephemeral ports) instead of hardcoded 8118 to prevent EADDRINUSE collisions in CI runners.
  • Retry Logic: Increased the test timeout to 90s to accommodate exponential backoff delays and CI environment latency.
  • Lifecycle Management: Wrapped assertions in try/catch to ensure mockServer.close() is always called, preventing socket leaks.
  • Async Fix: Corrected a race condition in the non-responsive host test where done() was being called before the retry cycle completed.

Impact

Reduces "Exit Status 1" build failures in Kokoro CI, improving the stability of the continuous integration pipeline for the Node.js Storage library.

Testing

  • System Tests: Verified locally via npm run system-test.
  • Telemetry: Inspected retry cycles using NODE_DEBUG=http to confirm the library correctly registers all 4 attempts before concluding.
  • Cleanup: Confirmed no orphaned processes or open sockets remain after test completion.

Additional Information

The original 60s timeout was frequently exceeded during the 4-attempt retry cycle when the CI runner was under heavy load. The move to dynamic ports is the primary structural fix to prevent cross-test interference.

Checklist

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease
  • Appropriate docs were updated
  • Appropriate comments were added, particularly in complex areas or places that require background
  • No new warnings or issues will be generated from this change

Fixes #issue_number_goes_here 🦕

- Implement dynamic port allocation (port 0) for mock servers to avoid
EADDRINUSE collisions in CI.
- Increase timeout to 90s for retry logic to accommodate environmental
latency.
- Ensure mock servers are explicitly closed in both success and failure
blocks.
- Fix async race condition in 'non-responsive hosts' test by moving
done() into the callback.
@gemini-code-assist
Copy link

Summary of Changes

Hello @thiyaguk09, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request aims to significantly improve the stability of the Service system tests by resolving intermittent flakiness and timeouts. The primary issues addressed include EADDRINUSE errors caused by hardcoded ports in parallel test execution and test failures due to insufficient timeouts under heavy CI load. By implementing dynamic port allocation, extending test timeouts, and enhancing resource cleanup, the changes are expected to reduce 'Exit Status 1' build failures in Kokoro CI, leading to a more reliable continuous integration pipeline.

Highlights

  • Dynamic Port Allocation: Refactored mock servers to use ephemeral port 0 instead of a hardcoded port (8118) to prevent EADDRINUSE errors, especially in parallel CI test runs.
  • Increased Test Timeout: The system test timeout was increased to 90 seconds to accommodate potential exponential backoff delays and general CI environment latency, reducing premature test failures.
  • Robust Lifecycle Management: Implemented try/catch blocks around test assertions to guarantee that mockServer.close() is always invoked, preventing socket leaks and ensuring proper resource cleanup.
  • Race Condition Fix: Addressed a race condition in the non-responsive host test by moving the done() callback to ensure it's executed only after the full retry cycle has completed, preventing premature test termination.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • system-test/common.ts
    • Added a comment clarifying the use of MOCK_HOST_PORT for service initialization while individual tests use dynamic ports.
    • Modified mock server setup to listen on port 0 (ephemeral port) and dynamically retrieve the assigned port for service.request calls.
    • Wrapped assertion logic in try/catch blocks within test callbacks to ensure mockServer.close() is always called, even if assertions fail.
    • Updated the URI for the 'should retry non-responsive hosts' test to http://localhost:1/mock-endpoint-no-response to reliably trigger ECONNREFUSED.
    • Corrected the placement of the done() callback in the non-responsive host test to resolve a race condition, ensuring it's called after the request's retry cycle.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses intermittent test failures by introducing several robust improvements. Using ephemeral ports for mock servers is a great change to prevent port conflicts in CI. The addition of try/catch blocks ensures proper server cleanup, preventing resource leaks, and the fix for the asynchronous race condition in the non-responsive host test is crucial for test reliability. My review includes a couple of minor suggestions to improve type safety by avoiding as any when retrieving the server port.

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.

1 participant