Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Flaky tests are common occurrences in open-source projects, yielding inconsistent results—sometimes passing and sometimes failing—without code changes. I have fixed 5 flaky tests, which are listRetryTask(), deleteRetryTask() in easy-retry/easy-retry-extensions/easy-retry-mybatis-extension/src/test/java/com/alibaba/easyretry/extension/mybatis/dao/RetryTaskDAOImplTest.java and handle(), stop() and finish() in easy-retry/easy-retry-extensions/easy-retry-mybatis-extension/src/test/java/com/alibaba/easyretry/extension/mybatis/access/MybatisRetryTaskAccessTest.java.
Root cause
The root cause of these flaky tests was related to orders of execution of the tests who locate in the same class. For the RetryTaskDAOImplTest class, it need to run saveTask() firstly, if not, the listRetryTask() and deleteRetryTask() will fail.
For the MybatisRetryTaskAccessTest class, it need to run saveTask() firstly, if not, the tests handle(), stop() and finish() will fail.
Fix
This test has been resolved by extracting the patches from saveTask() that will create a task and save it firstly, and put the patches in front of the line of assert tests that fail in each order-dependent flaky tests. Then all order-dependent flaky tests pass.
How to test
Java: openjdk version "11.0.20.1"
Maven: Apache Maven 3.6.3
mvn install -pl easy-retry-extensions/easy-retry-mybatis-extension -am -DskipTests
mvn -pl easy-retry-extensions/easy-retry-mybatis-extension test -Dtest=com.alibaba.easyretry.extension.mybatis.dao.RetryTaskDAOImplTest#listRetryTask
mvn -pl easy-retry-extensions/easy-retry-mybatis-extension test -Dtest=com.alibaba.easyretry.extension.mybatis.dao.RetryTaskDAOImplTest#deleteRetryTask
mvn -pl easy-retry-extensions/easy-retry-mybatis-extension test -Dtest=com.alibaba.easyretry.extension.mybatis.access.MybatisRetryTaskAccessTest#stop
mvn -pl easy-retry-extensions/easy-retry-mybatis-extension test -Dtest=com.alibaba.easyretry.extension.mybatis.access.MybatisRetryTaskAccessTest#finish
mvn -pl easy-retry-extensions/easy-retry-mybatis-extension test -Dtest=com.alibaba.easyretry.extension.mybatis.access.MybatisRetryTaskAccessTest#handle
All tests should pass.