Skip to content

Commit 9e69e5b

Browse files
committed
Make Execution control consistent
Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent bfcea72 commit 9e69e5b

File tree

6 files changed

+54
-32
lines changed

6 files changed

+54
-32
lines changed

.idea/kotlin-statistics.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ testing {
5050
implementation(libs.mockito.core)
5151
implementation(libs.spring.beans)
5252
implementation(libs.json.assert)
53+
implementation(libs.assertj.vavr)
5354
}
5455
}
5556
}

src/integrationTest/java/com/salesforce/revoman/integration/pokemon/PokemonTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static com.salesforce.revoman.input.config.StepPick.PostTxnStepPick.afterStepName;
1717
import static com.salesforce.revoman.input.config.StepPick.PreTxnStepPick.beforeStepContainingHeader;
1818
import static com.salesforce.revoman.input.config.StepPick.PreTxnStepPick.beforeStepName;
19+
import static org.assertj.vavr.api.VavrAssertions.assertThat;
1920
import static org.mockito.ArgumentMatchers.any;
2021
import static org.mockito.Mockito.times;
2122

@@ -27,6 +28,7 @@
2728
import com.salesforce.revoman.output.report.Step;
2829
import com.salesforce.revoman.output.report.StepReport;
2930
import com.salesforce.revoman.output.report.TxnInfo;
31+
import com.salesforce.revoman.output.report.failure.HookFailure.PostStepHookFailure;
3032
import java.util.List;
3133
import java.util.Map;
3234
import org.http4k.core.Request;
@@ -45,6 +47,8 @@ class PokemonTest {
4547
private static final int LIMIT = 3;
4648
private static final int OFFSET = 0;
4749
private static final Logger LOGGER = LoggerFactory.getLogger(PokemonTest.class);
50+
private static final RuntimeException RUNTIME_EXCEPTION =
51+
new RuntimeException("This won't interrupt the execution as `haltOnAnyFailure` is not set");
4852

4953
@Test
5054
void pokemon() {
@@ -72,6 +76,7 @@ public void accept(
7276
@Override
7377
public void accept(@NotNull StepReport stepReport, @NotNull Rundown rundown) {
7478
LOGGER.info("Picked `postLogHook` after stepName: {}", stepReport.step.displayName);
79+
throw RUNTIME_EXCEPTION;
7580
}
7681
});
7782
//noinspection Convert2Lambda
@@ -123,10 +128,10 @@ public void accept(@NotNull StepReport stepReport, @NotNull Rundown rundown) {
123128
pre(beforeStepContainingHeader("preLog"), preLogHook),
124129
post(afterStepContainingHeader("postLog"), postLogHook))
125130
.dynamicEnvironment(dynamicEnvironment)
126-
.haltOnAnyFailure(true)
127131
.off());
128132

129-
assertThat(pokeRundown.firstUnIgnoredUnsuccessfulStepReport()).isNull();
133+
assertThat(pokeRundown.firstUnIgnoredUnsuccessfulStepReport().failure)
134+
.containsOnLeft(new PostStepHookFailure(RUNTIME_EXCEPTION));
130135
assertThat(pokeRundown.stepReports).hasSize(5);
131136
assertThat(pokeRundown.mutableEnv)
132137
.containsExactlyEntriesIn(

src/main/kotlin/com/salesforce/revoman/input/config/KickDef.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal interface KickDef {
4848

4949
@Value.Default fun haltOnAnyFailure(): Boolean = false
5050

51-
fun haltOnFailureOfTypeExcept(): Map<ExeType, PostTxnStepPick>?
51+
fun haltOnFailureOfTypeExcept(): Map<ExeType, PostTxnStepPick>
5252

5353
fun runOnlySteps(): List<ExeStepPick>
5454

@@ -94,8 +94,8 @@ internal interface KickDef {
9494

9595
@Value.Check
9696
fun validateConfig() {
97-
require(!haltOnAnyFailure() || (haltOnAnyFailure() && haltOnFailureOfTypeExcept() == null)) {
98-
"`haltOnAnyFailureExcept` should NOT be set when `haltOnAnyFailure` is set to `True`"
97+
require(!haltOnAnyFailure() || (haltOnAnyFailure() && haltOnFailureOfTypeExcept().isEmpty())) {
98+
"`haltOnAnyFailureExcept` should NOT be set when `haltOnAnyFailure` is set to true"
9999
}
100100
require(disjoint(runOnlySteps(), skipSteps())) {
101101
"`runOnlySteps` and `skipSteps` cannot contain same step names"

src/main/kotlin/com/salesforce/revoman/internal/exe/ExeUtils.kt

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,34 +98,41 @@ internal fun shouldHaltExecution(
9898
): Boolean =
9999
when {
100100
currentStepReport.isSuccessful -> false
101-
kick.haltOnAnyFailure() -> {
102-
logger.info {
103-
"${currentStepReport.step} failed with ${currentStepReport.failure}, 🛑 halting the execution, as haltOnAnyFailure=true"
104-
}
105-
true
106-
}
107101
else -> {
108-
kick
109-
.haltOnFailureOfTypeExcept()
110-
?.asSequence()
111-
?.map { (exeType, postTxnPick) ->
112-
currentStepReport.exeTypeForFailure == exeType &&
113-
postTxnPick.pick(
114-
currentStepReport,
115-
pm.rundown.copy(stepReports = pm.rundown.stepReports + currentStepReport),
116-
)
102+
logger.info { "${currentStepReport.step} failed with ${currentStepReport.failure}" }
103+
when {
104+
kick.haltOnAnyFailure() -> {
105+
logger.info { "🛑 Halting the execution, as `haltOnAnyFailure` is set to true" }
106+
true
117107
}
118-
?.any { it }
119-
?.also {
108+
kick.haltOnFailureOfTypeExcept().isEmpty() -> {
120109
logger.info {
121-
if (it) {
122-
"${currentStepReport.step} failed, but ignoring failure, as it qualifies haltOnFailureOfTypeExcept for ${currentStepReport.exeTypeForFailure}"
123-
} else {
124-
"${currentStepReport.step} failed, and doesn't qualify for haltOnAnyFailureExcept for ${currentStepReport.exeTypeForFailure}, so 🛑 halting the execution"
125-
}
110+
"Continuing the execution, as `haltOnAnyFailure` is set to false and `haltOnFailureOfTypeExcept` is empty"
126111
}
112+
false
127113
}
128-
?.not() != false
114+
else ->
115+
kick
116+
.haltOnFailureOfTypeExcept()
117+
.asSequence()
118+
.any { (exeType, postTxnPick) ->
119+
currentStepReport.exeTypeForFailure == exeType &&
120+
postTxnPick.pick(
121+
currentStepReport,
122+
pm.rundown.copy(stepReports = pm.rundown.stepReports + currentStepReport),
123+
)
124+
}
125+
.not()
126+
.also {
127+
logger.info {
128+
if (it) {
129+
"${currentStepReport.step} doesn't qualify `haltOnFailureOfTypeExcept` for ${currentStepReport.exeTypeForFailure}, so 🛑 halting the execution"
130+
} else {
131+
"Continuing the execution, as the step qualifies `haltOnFailureOfTypeExcept` for ${currentStepReport.exeTypeForFailure}"
132+
}
133+
}
134+
}
135+
}
129136
}
130137
}
131138

src/main/kotlin/com/salesforce/revoman/internal/postman/PostmanSDK.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class PostmanSDK(
3838
lateinit var request: Request
3939
lateinit var response: Response
4040
lateinit var currentStepReport: StepReport
41-
@Suppress("unused")
42-
@JvmField val variables: Variables = Variables()
41+
@Suppress("unused") @JvmField val variables: Variables = Variables()
4342
lateinit var rundown: Rundown
4443
@JvmField val xml2Json = Xml2Json { xml -> moshiReVoman.asA(U.xmlToJson(xml)) }
4544
// * NOTE 28 Apr 2024 gopala.akshintala: This has to be initialized at last
@@ -120,12 +119,16 @@ class PostmanSDK(
120119
fun get(key: String) = environment[key]
121120

122121
fun set(key: String, value: String) {
123-
logger.info { "pm environment variable set through JS in Step: ${currentStepReport.step} - key: $key, value: ${pprint(value)}" }
122+
logger.info {
123+
"pm environment variable set through JS in Step: ${currentStepReport.step} - key: $key, value: ${pprint(value)}"
124+
}
124125
environment.set(key, value)
125126
}
126127

127128
fun unset(key: String) {
128-
logger.info { "pm environment variable unset through JS in Step: ${currentStepReport.step} - key: $key" }
129+
logger.info {
130+
"pm environment variable unset through JS in Step: ${currentStepReport.step} - key: $key"
131+
}
129132
environment.unset(key)
130133
}
131134

0 commit comments

Comments
 (0)