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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix flaky #28

wants to merge 2 commits into from

Conversation

Carol7102
Copy link

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

  1. Compile the module
    mvn install -pl easy-retry-extensions/easy-retry-mybatis-extension -am -DskipTests
  2. Run tests for each test
    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.

@CLAassistant
Copy link

CLAassistant commented Nov 27, 2023

CLA assistant check
All committers have signed the CLA.

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.

None yet

2 participants