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 exportDomainArtifacts #1

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

Conversation

dserfe
Copy link
Owner

@dserfe dserfe commented Sep 24, 2023

This PR is to fix a flaky test io.github.dddplus.runtime.registry.IntegrationTest#exportDomainArtifacts in module dddplus-test.

Setup:

Java version: 1.8.0_382
Maven version: Apache Maven 3.6.3

Test failure Reproduction:

Test io.github.dddplus.runtime.registry.IntegrationTest.exportDomainArtifacts can fail as the underlying code uses a HashMap and assumes the order of values returned by the .values() function. This issue was verified using the NonDex plugin.

Steps:

git clone https://github.com/funkygao/cp-ddd-framework
cd cp-ddd-framework
mvn install -pl dddplus-test -am -DskipTests
mvn -pl dddplus-test edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=io.github.dddplus.runtime.registry.IntegrationTest#exportDomainArtifacts -DnondexMode=ONE

NonDex test failure:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.002 s <<< FAILURE! - in io.github.dddplus.runtime.registry.IntegrationTest
[ERROR] io.github.dddplus.runtime.registry.IntegrationTest.exportDomainArtifacts  Time elapsed: 0.001 s  <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException: 0
	at io.github.dddplus.runtime.registry.IntegrationTest.exportDomainArtifacts(IntegrationTest.java:617)

The tool flags the test as failed even in the ONE mode, which means that the map's keys are shuffled only once and every call to the map produces the same shuffled order.

Root cause and fix:

The test has been setup to register 4 submit activities with codes Bar, Baz, Foo and Ham as indicated by debug logs:

2023-09-23 10:28:19,966 [main] DEBUG [io.github.dddplus.runtime.registry.InternalIndexer] [232] - indexed StepDef(activity=Submit, code=Bar, name=, tags=[goodsValidation], stepBean=io.github.dddplus.runtime.registry.mock.step.BarStep@2d8f2f3a) 
2023-09-23 10:28:19,980 [main] DEBUG [io.github.dddplus.runtime.registry.InternalIndexer] [232] - indexed StepDef(activity=Submit, code=Baz, name=, tags=[], stepBean=io.github.dddplus.runtime.registry.mock.step.BazStep@2024293c) 
2023-09-23 10:28:19,981 [main] DEBUG [io.github.dddplus.runtime.registry.InternalIndexer] [232] - indexed StepDef(activity=Cancel, code=Egg, name=, tags=[], stepBean=io.github.dddplus.runtime.registry.mock.step.EggStep@7048f722) 
2023-09-23 10:28:19,992 [main] DEBUG [io.github.dddplus.runtime.registry.InternalIndexer] [232] - indexed StepDef(activity=Submit, code=Foo, name=foo活动, tags=[goodsValidation], stepBean=io.github.dddplus.runtime.registry.mock.step.FooStep@58a55449) 
2023-09-23 10:28:19,994 [main] DEBUG [io.github.dddplus.runtime.registry.InternalIndexer] [232] - indexed StepDef(activity=Submit, code=Ham, name=, tags=[], stepBean=io.github.dddplus.runtime.registry.mock.step.HamStep@5949eba8) 

Only Foo and Bar steps have a goodsValidation tag.

The DomainArtifacts.Step objects for a specific activity (Steps.Submit.Activity in this case), are added as a list of values to a map, with key as activity here. The 1st element of this list is asserted to have a goodsValidation tag in the test here. This expectation fails when the first element of the list is neither Foo nor Bar.

The list will not guarantee any ordering, as it is being populated in the order returned by .values() here, of a HashMap here, which itself makes no guarentees on order.

To fix the test expectation, we only filter for steps that have a non empty tag and assert that any of these steps tags have a value of goodsValidation, instead of the first one. This removes test flakiness with minimal changes.
The latest test expectation does not look at: a) which specific step has this tag and b) how many steps have the tag, as the original test does not have any expectation/assertions for these. The change continues to maintain this test logic.

The test was rerun using the NonDex plugin and passes after the fix.

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