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 org.aim42.htmlsanitycheck.check.BrokenCrossReferencesCheckerTest.testTwoBrokenLinks #311

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

hofi1
Copy link

@hofi1 hofi1 commented Oct 23, 2023

Problem

The test org.aim42.htmlsanitycheck.check.BrokenCrossReferencesCheckerTest.testTwoBrokenLinks asserts the finding of the SingleCheckResults. These findings are stored in a Set. But the order, in which the two given findings are returned by the set, is not deterministic. The test expects the values to be in certain order. This leads to a flaky test.

void testTwoBrokenLinks() {
String HTML_WITH_TWO_LINKS_NO_ID = '''
<a href="#aim42">link-to-aim42</a>
<a href="#arc42">non-existing-link</a>
'''
check HTML_WITH_TWO_LINKS_NO_ID
assertEquals( "expected two findings", 2, collector.nrOfProblems())
assertEquals( "expected four checks", 4, collector.nrOfItemsChecked)
// first finding: aim42 link missing
String actual = collector.findings.first()
String expected = "link target \"aim42\" missing"
String message = "expected $expected"
assertEquals(message, expected, actual)
// second finding: arc42 link missing
actual = collector.findings[1]
expected = "link target \"arc42\" missing"
assertEquals(message, expected, actual)
}

This problem was found by the NonDex Engine.

Solution

Sort the set, to make sure, it is returned in predefined order.

Reproduce

To reproduce follow the steps:

  1. ./gradlew build -x test
  2. Add the following text to the top of the build.gradle file in $PROJ_DIR.
buildscript {
    repositories {
      maven {
        url = uri('https://plugins.gradle.org/m2/')
      }
    }
    dependencies {
      classpath('edu.illinois:plugin:2.1.1')
    }
}
  1. Add the following line to the end of the build.gradle file in $PROJ_DIR.
apply plugin: 'edu.illinois.nondex'
  1. Run
./gradlew --info nondexTest --tests=org.aim42.htmlsanitycheck.check.BrokenCrossReferencesCheckerTest.testTwoBrokenLinks --nondexRuns=50

@hofi1 hofi1 closed this Oct 23, 2023
Copy link
Member

@gernotstarke gernotstarke left a comment

Choose a reason for hiding this comment

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

thanx, good improvement!

@gernotstarke gernotstarke reopened this Oct 24, 2023
@gernotstarke gernotstarke merged commit fa8b073 into aim42:main Oct 24, 2023
1 check passed
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.

2 participants