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

fix flaky test. #1663

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

methane
Copy link
Member

@methane methane commented Jan 23, 2025

Description

TestIssue1567 fails by max_connections error. This makes our CI unhappy.

https://github.com/go-sql-driver/mysql/actions/runs/12904961433/job/35984402310

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

Summary by CodeRabbit

  • Bug Fixes
    • Improved test robustness by dynamically adapting to MySQL server connection limits
    • Added safeguards to prevent exceeding maximum allowed concurrent connections during testing

@methane methane requested a review from shogo82148 January 23, 2025 10:50
Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request modifies the TestIssue1567 function in driver_test.go to dynamically retrieve and respect the maximum number of connections allowed by the MySQL server. The changes introduce a mechanism to query the server's max_connections configuration and adjust the test's connection ping loop accordingly, ensuring the test does not exceed the server's connection limits.

Changes

File Change Summary
driver_test.go - Added query to retrieve max_connections from MySQL server
- Implemented error handling for connection max retrieval
- Modified ping test loop to respect server's connection limit

Possibly related PRs

Suggested reviewers

  • shogo82148

Poem

🐰 A MySQL test hops along the wire,
Checking connections, never to tire
Max connections learned with grace,
Pinging servers at a measured pace
Robust testing, rabbit's delight! 🔍

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
driver_test.go (1)

Line range hint 3611-3638: Consider adding debug logging for better test observability.

The fix looks good, but consider these improvements for better debugging and maintainability:

  1. Add debug logging when the count is reduced due to max_connections limit.
  2. Add a comment explaining why we need to respect max_connections.

Here's a suggested improvement:

 var max int
 err := dbt.db.QueryRow("SELECT @@max_connections").Scan(&max)
 if err != nil {
     dbt.Fatalf("%s", err.Error())
 }

 // disable connection pooling.
 // data race happens when new connection is created.
 dbt.db.SetMaxIdleConns(0)

 // estimate round trip time.
 start := time.Now()
 if err := dbt.db.PingContext(context.Background()); err != nil {
     t.Fatal(err)
 }
 rtt := time.Since(start)
 if rtt <= 0 {
     // In some environments, rtt may become 0, so set it to at least 1ms.
     rtt = time.Millisecond
 }

 count := 1000
 if testing.Short() {
     count = 10
 }
+// Ensure we don't exceed the server's max_connections limit to prevent
+// "Too many connections" errors that can make the test flaky
 if count > max {
+    t.Logf("Reducing connection count from %d to %d due to server's max_connections limit", count, max)
     count = max
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85c6311 and 7944155.

📒 Files selected for processing (1)
  • driver_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: test (windows-latest, 1.23, mariadb-10.5)
  • GitHub Check: test (windows-latest, 1.23, mariadb-10.6)
  • GitHub Check: test (windows-latest, 1.23, mariadb-10.11)
  • GitHub Check: test (windows-latest, 1.23, mariadb-11.1)
  • GitHub Check: test (windows-latest, 1.23, mariadb-11.2)
  • GitHub Check: test (windows-latest, 1.23, mariadb-11.4)
  • GitHub Check: test (windows-latest, 1.23, 5.7)
  • GitHub Check: test (windows-latest, 1.23, 8.0)
  • GitHub Check: test (windows-latest, 1.23, 8.4)
  • GitHub Check: test (windows-latest, 1.23, 9.0)
  • GitHub Check: test (macos-latest, 1.23, mariadb-10.5)
  • GitHub Check: test (macos-latest, 1.23, mariadb-10.6)
  • GitHub Check: test (macos-latest, 1.23, mariadb-10.11)
  • GitHub Check: test (macos-latest, 1.23, mariadb-11.1)
  • GitHub Check: test (macos-latest, 1.23, mariadb-11.4)
🔇 Additional comments (2)
driver_test.go (2)

3611-3615: LGTM! Good addition to prevent connection limit issues.

Querying the server's max_connections limit is a good approach to ensure the test doesn't exceed the server's capacity.


3636-3638: LGTM! Good safeguard against connection limit exceeded errors.

Capping the test count to max_connections ensures the test won't attempt to create more connections than the server allows, fixing the flaky behavior.

@coveralls
Copy link

Coverage Status

coverage: 82.958% (-0.1%) from 83.06%
when pulling 7944155 on methane:fix-flaky-test
into 85c6311 on go-sql-driver:master.

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