Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)


import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration

@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])
open class FlakinessDetectApplication {
companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(FlakinessDetectApplication::class.java, *args)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.foo.rest.examples.spring.openapi.v3.flakinessdetect

import org.h2.util.MathUtils.randomInt
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.math.max
import kotlin.math.min

@RestController
@RequestMapping(path = ["/api/flakinessdetect"])
class FlakinessDetectRest {

companion object{
val formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS yyyy-MM-dd EEEE 'Week' ww")
}

@GetMapping(path = ["/stringfirst/{n}"])
open fun getFirst( @PathVariable("n") n: Int) : ResponseEntity<String> {

return ResponseEntity.ok(getPartialDate(n))
}

@GetMapping(path = ["/next/{n}"])
open fun getNext( @PathVariable("n") n: Int) : ResponseEntity<FlakinessDetectData> {

return ResponseEntity.ok(FlakinessDetectData(getPartialDate(n), randomInt(n)))
}


private fun getPartialDate(n: Int) : String {
val now = LocalDateTime.now().format(formatter)
val size = max(12, min(now.toString().length, n))

return now.substring(0, size)
}
}

data class FlakinessDetectData(val first : String, val next : Int)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.foo.rest.examples.spring.openapi.v3.flakinessdetect

import com.foo.rest.examples.spring.openapi.v3.SpringController

class FlakinessDetectController : SpringController(FlakinessDetectApplication::class.java)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.evomaster.e2etests.spring.openapi.v3.flakinessdetect

import com.foo.rest.examples.spring.openapi.v3.flakinessdetect.FlakinessDetectController
import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import java.nio.file.Files
import java.nio.file.Paths

class FlakinessDetectEMTest : SpringTestBase() {

companion object {
@BeforeAll
@JvmStatic
fun init() {
initClass(FlakinessDetectController())
}
}


@Test
fun testRunEM() {
runTestHandlingFlakyAndCompilation(
"FlakinessDetectEM",
"org.foo.FlakinessDetectEM",
5
) { args: MutableList<String> ->

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

args.add("true")
args.add("--detectFlakiness")
args.add("true")


val solution = initAndRun(args)

val size = Files.readAllLines(Paths.get(executedMainActionToFile)).count { !it.contains("Flaky") && it.isNotBlank() }
assertTrue(size >= 3)
}
}
}
4 changes: 4 additions & 0 deletions core/src/main/kotlin/org/evomaster/core/EMConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,10 @@ class EMConfig {
RANDOM
}

@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


@Experimental
@Cfg("Specify a method to select the first external service spoof IP address.")
var externalServiceIPSelectionStrategy = ExternalServiceIPSelectionStrategy.NONE
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/kotlin/org/evomaster/core/output/Lines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ class Lines(val format: OutputFormat) {
buffer[buffer.lastIndex] = buffer.last().replace(regex, replacement)
}

fun replaceFirstInCurrent(regex: Regex, replacement: String){
Copy link
Collaborator

Choose a reason for hiding this comment

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

add JavaDoc

if(buffer.isEmpty()){
return
}

buffer[buffer.lastIndex] = buffer.last().replaceFirst(regex, replacement)
}

/**
* Is the current line just a comment // without any statement?
*/
Expand Down
Loading