Skip to content

Conversation

@man-zhang
Copy link
Contributor

Detect flakiness during post-handling of fuzzing

  • if minimization is enabled, then process the detection within minimization,
  • otherwise, re-execute individuals

Comment out assertions at the field level.
Currently support only for JUnit with white-box mode

@man-zhang man-zhang requested a review from arcuri82 January 14, 2026 09:14

val executedMainActionToFile = "target/em-tests/FlakinessDetectEM/org/foo/FlakinessDetectEM.kt"

args.add("--minimize")
Copy link
Collaborator

Choose a reason for hiding this comment

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

for new E2E tests, should use setOption

'[' -> {
try{
// This would be run if the JSON contains an array of objects.
val list = Gson().fromJson(bodyString, List::class.java)
Copy link
Collaborator

Choose a reason for hiding this comment

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

whe should NOT use Gson for new code. Gson has major design flows (and really nasty "features" on by default...). use Jackson for new code (at a certain point, we will need to get rid off Gson from EM codebase, but it is not high priority)

try {
val resContents = Gson().fromJson(bodyString, Map::class.java)
handleAssertionsOnObject(resContents as Map<String, *>, lines, "", bodyVarName)
val flakyMap = flakyBodyString?.let { Gson().fromJson(it, Map::class.java) as Map<String, *> }
Copy link
Collaborator

Choose a reason for hiding this comment

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

see previous comment on Gson

val value = bodyIsString(s,GeneUtils.EscapeMode.BODY, responseVariableName)

val fs = flakyBodyString?.trim()
if (fs == null || fs == s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

always use {} brackets, even for single statement in a if

try {
val number = s.toDouble()
handleAssertionsOnField(number, lines, fieldPath, responseVariableName)
// TODO only support flaky for JVM
Copy link
Collaborator

Choose a reason for hiding this comment

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

why only for JVM? base flakiness handling should be in Black-Box as well

minimizer.simplifyActions()
val seconds = minimizer.passedTimeInSecond()
LoggingUtil.getInfoLogger().info("Minimization phase took $seconds seconds")
} else if (config.detectFlakiness){
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't be done here, as it will miss all the test cases generated after the "search".
Look at Main class with:

            //apply new phases
            solution = phaseHttpOracle(injector, config, solution)
            solution = phaseSecurity(injector, config, epc, solution)

maybe flakiness should be a new "phase" (recorded in ExecutionPhaseController), which is executed last

}
""".trimIndent()
assertEquals(expectedLines, lines.toString())
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a very brittle assertion. it will start failing as soon as we make any cosmetic change in the generation of test.
could rather check for presence of // Flaky value (which anyway should in a const val shared between production code and tests), and/or number of // in the generated code

}
""".trimIndent()
assertEquals(expectedLines, lines.toString())
Copy link
Collaborator

Choose a reason for hiding this comment

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

very brittle assertion


@Experimental
@Cfg("Specify whether to detect flaky assertions during post handling of fuzzing.")
var detectFlakiness = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

not only detect, but also handle, isn't it? maybe rename into handleFlakiness. also, in Cfg documentation, specify that flaky assertions will be commented out

@@ -0,0 +1,15 @@
package com.foo.rest.examples.spring.openapi.v3.flakinessdetect
Copy link
Collaborator

Choose a reason for hiding this comment

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

when dealing with PR where test output code is changed/upgraded, should also have 1 BB test under core-tests/e2e-tests/spring/spring-rest-bb, as those automatically check all output formats (eg Python and JS)

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.

3 participants