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 #387

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

Conversation

Alisha-0321
Copy link

What changes were proposed in this pull request?

I observe that a test (info.archinnov.achilles.it.TestALLEntityAsChild.should_insert) is a flaky test than can fail due to the slow execution of achilles-embedded/src/main/java/info/archinnov/achilles/embedded/ServerStarter#L159. When ServerStarter.java#159 is not executed quick enough, the method (initializeFromParameters) tries to connect the cluster given at Line 63, then fails. While it may be possible to fix this flaky test by adding a waiting time before the execution of this line, but I believe such a fix might be unstable in a CI environment or when run on different machines, given the dependency on some constant wait time. Hence, I suggest a new way to fix the test by adding some synchronization for the test execution only. I at first identify the code location that needs to be executed before making the connection with the cluster (achilles-embedded/src/main/java/info/archinnov/achilles/embedded/ServerStarter#L159), so I introduce one variable in this class that is only there to provide some synchronization. Basically, until these statements are executed, I force the thread that the test runs to wait before it proceeds to the assertions.

Why are the changes needed?

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 30.377 s <<< FAILURE! - in info.archinnov.achilles.it.TestALLEntityAsChild
[ERROR] should_insert(info.archinnov.achilles.it.TestALLEntityAsChild) Time elapsed: 30.377 s <<< ERROR!
com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [localhost/127.0.0.1:9042] Cannot connect))
at info.archinnov.achilles.it.TestALLEntityAsChild.(TestALLEntityAsChild.java:49)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] TestALLEntityAsChild.:49 » NoHostAvailable All host(s) tried for query f...
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

How was this patch tested?

I run this test more than 1000 times and the test always passes.

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