Skip to content

Fix flaky test JedisPoolTest.testCloseConnectionOnMakeObject #4138

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

Merged
merged 5 commits into from
Apr 7, 2025

Conversation

thachlp
Copy link
Contributor

@thachlp thachlp commented Apr 7, 2025

The test JedisPoolTest.testCloseConnectionOnMakeObject occasionally fails with the following error:

`JedisPoolTest.testCloseConnectionOnMakeObject:403 expected:<4> but was:<5>`

Root Cause:
The assertion is based on the output of getClientCount(jedis.clientList()), which is called immediately after closing a connection. However, Redis may take a short time to remove the closed connection from the client list, leading to a transient count mismatch and a flaky test result.

Example stack trace:

Error:  redis.clients.jedis.JedisPoolTest.testCloseConnectionOnMakeObject -- Time elapsed: 0.006 s <<< FAILURE!
java.lang.AssertionError: expected:<4> but was:<5>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at org.junit.Assert.assertEquals(Assert.java:633)
	at redis.clients.jedis.JedisPoolTest.testCloseConnectionOnMakeObject(JedisPoolTest.java:403)

closes #4135

@ggivo
Copy link
Collaborator

ggivo commented Apr 7, 2025

@thachlp
Thanks for looking into the issue!
I think using Awaitility would simplify things.

@ggivo ggivo added testing maintenance skip-changelog Ignore pull request from release note labels Apr 7, 2025
Copy link
Contributor Author

@thachlp thachlp left a comment

Choose a reason for hiding this comment

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

Thank @thachlp for helping me update the description.
Btw, I tried to run format and validate and it was successful, but it still fail on check-format job.
What do I miss? 🙇

@thachlp thachlp requested a review from ggivo April 7, 2025 08:00
@ggivo
Copy link
Collaborator

ggivo commented Apr 7, 2025

Thank @thachlp for helping me update the description. Btw, I tried to run format and validate and it was successful, but it still fail on check-format job. What do I miss? 🙇

Since code formatting was not enforced there are lots of discrepancies in the code. We are currently experimenting with how to enforce it. [Java Format Check] is optional currently and serves as a hint to reviewers that the code is not properly formatted. You can discard it for now. In case formatting the whole file introduces lots of additional formatting changes and makes the review harder my advice is to format only the modified code. Code formatting rules can be found hbase-formatter.xml.

PS: mvn formatter:format will reformat only sources described here
https://github.com/ggivo/jedis/blob/a4d2b8d062a3ecb878750f83abe0439f01100739/pom.xml#L329-L329

@thachlp thachlp requested a review from ggivo April 7, 2025 08:37
@ggivo ggivo changed the title Fix flaky test Fix flaky test JedisPoolTest.testCloseConnectionOnMakeObject Apr 7, 2025
Copy link
Collaborator

@ggivo ggivo left a comment

Choose a reason for hiding this comment

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

LGTM

@ggivo ggivo merged commit 8e78a93 into redis:master Apr 7, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance skip-changelog Ignore pull request from release note testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix flaky test JedisPoolTest.testCloseConnectionOnMakeObject
2 participants