Skip to content

Commit

Permalink
Save schedule when error found by JUnit plugin. (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al authored Dec 14, 2024
1 parent c3be45c commit 910d201
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion junit/src/main/kotlin/FrayExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FrayExtension(
extensionContext: ExtensionContext
): T {
frayContext.config.currentIteration = index
if (frayContext.config.currentIteration != 0) {
if (frayContext.config.currentIteration != 1) {
frayContext.config.scheduler = frayContext.config.scheduler.nextIteration()
frayContext.config.randomnessProvider = ControlledRandom()
}
Expand Down Expand Up @@ -50,6 +50,7 @@ class FrayExtension(

override fun testFailed(context: ExtensionContext, cause: Throwable) {
frayJupiterContext.bugFound = true
frayContext.reportError(cause)
}

override fun evaluateExecutionCondition(context: ExtensionContext?): ConditionEvaluationResult {
Expand Down
24 changes: 18 additions & 6 deletions junit/src/main/kotlin/FrayTestExtension.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.pastalab.fray.junit

import java.io.File
import java.lang.reflect.Method
import java.nio.file.Paths
import java.util.stream.Stream
import kotlin.io.path.absolutePathString
import kotlin.io.path.createTempDirectory
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.TestTemplateInvocationContext
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
Expand All @@ -17,6 +18,7 @@ import org.pastalab.fray.core.command.ExecutionInfo
import org.pastalab.fray.core.command.LambdaExecutor
import org.pastalab.fray.core.randomness.ControlledRandom
import org.pastalab.fray.core.scheduler.POSScheduler
import org.pastalab.fray.core.scheduler.Scheduler
import org.pastalab.fray.junit.annotations.ConcurrencyTest

class FrayTestExtension : TestTemplateInvocationContextProvider {
Expand All @@ -40,8 +42,18 @@ class FrayTestExtension : TestTemplateInvocationContextProvider {
if (!workDir.toFile().exists()) {
workDir.toFile().mkdirs()
}
val workDir = createTempDirectory(this.workDir).absolutePathString()
val schedulerInfo = concurrencyTest.scheduler
val (scheduler, random) =
if (concurrencyTest.replay.isNotEmpty()) {
val path = concurrencyTest.replay
val randomPath = "${path}/random.json"
val schedulerPath = "${path}/schedule.json"
val randomnessProvider =
Json.decodeFromString<ControlledRandom>(File(randomPath).readText())
val scheduler = Json.decodeFromString<Scheduler>(File(schedulerPath).readText())
Pair(scheduler, randomnessProvider)
} else {
Pair(POSScheduler(), ControlledRandom())
}
val config =
Configuration(
ExecutionInfo(
Expand All @@ -51,11 +63,11 @@ class FrayTestExtension : TestTemplateInvocationContextProvider {
false,
-1,
),
workDir,
workDir.absolutePathString(),
totalRepetition(concurrencyTest, testMethod),
60,
POSScheduler(),
ControlledRandom(),
scheduler,
random,
false,
false,
true,
Expand Down
3 changes: 2 additions & 1 deletion junit/src/main/kotlin/annotations/ConcurrencyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import org.pastalab.fray.core.scheduler.Scheduler
)
@TestTemplate
annotation class ConcurrencyTest(
val value: Int,
val value: Int = 1,
val scheduler: KClass<out Scheduler> = POSScheduler::class,
val name: String = SHORT_DISPLAY_NAME,
val replay: String = ""
) {
companion object {

Expand Down

0 comments on commit 910d201

Please sign in to comment.