Skip to content

Commit

Permalink
feat: add crashLoadGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
notdryft committed Sep 9, 2024
1 parent 12a2f25 commit 007b663
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
13 changes: 12 additions & 1 deletion js/core/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,18 @@ const scn = scenario("scenario")
(session) => true
)
.stopLoadGeneratorIf("#{message}", (session) => true)
.stopLoadGeneratorIf((session) => "message", "#{condition}");
.stopLoadGeneratorIf((session) => "message", "#{condition}")
// crashLoadGenerator
.crashLoadGenerator("#{message}")
.crashLoadGenerator((session) => "message")
// crashLoadGeneratorIf
.crashLoadGeneratorIf("#{message}", "#{condition}")
.crashLoadGeneratorIf(
(session) => "message",
(session) => true
)
.crashLoadGeneratorIf("#{message}", (session) => true)
.crashLoadGeneratorIf((session) => "message", "#{condition}");

//registerPebbleExtensions((io.pebbletemplates.pebble.extension.Extension) null);

Expand Down
83 changes: 83 additions & 0 deletions js/core/src/structure/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,66 @@ export interface StopLoadGeneratorIfFunction<T extends Errors<T>> {
(message: SessionTo<string>, condition: SessionTo<boolean>): T;
}

export interface CrashLoadGeneratorFunction<T extends Errors<T>> {
/**
* Have the virtual user abruptly stop the load generator with a failed status
*
* @param message - the message, expressed as a Gatling Expression Language String
* @returns a new StructureBuilder
*/
(message: string): T;

/**
* Have the virtual user abruptly crash the load generator with a failed status
*
* @param message - the message, expressed as a function
* @returns a new StructureBuilder
*/
(message: SessionTo<string>): T;
}

export interface CrashLoadGeneratorIfFunction<T extends Errors<T>> {
/**
* Have the virtual user abruptly crash the load generator with a failed status if a condition is
* met
*
* @param message - the message, expressed as a Gatling Expression Language String
* @param condition - the condition, expressed as a Gatling Expression Language String
* @returns a new StructureBuilder
*/
(message: string, condition: string): T;

/**
* Have the virtual user abruptly crash the load generator with a failed status if a condition is
* met
*
* @param message - the message, expressed as a Gatling Expression Language String
* @param condition - the condition, expressed as a function
* @returns a new StructureBuilder
*/
(message: string, condition: SessionTo<boolean>): T;

/**
* Have the virtual user abruptly crash the load generator with a failed status if a condition is
* met
*
* @param message - the message, expressed as a function
* @param condition - the condition, expressed as a Gatling Expression Language String
* @returns a new StructureBuilder
*/
(message: SessionTo<string>, condition: string): T;

/**
* Have the virtual user abruptly crash the load generator with a failed status if a condition is
* met
*
* @param message - the message, expressed as a function
* @param condition - the condition, expressed as a function
* @returns a new StructureBuilder
*/
(message: SessionTo<string>, condition: SessionTo<boolean>): T;
}

export interface Errors<T extends Errors<T>> {
exitBlockOnFail: ExitBlockOnFailFunction<T>;
tryMax: TryMaxFunction<T>;
Expand All @@ -135,6 +195,8 @@ export interface Errors<T extends Errors<T>> {
exitHereIfFailed: ExitHereIfFailedFunction<T>;
stopLoadGenerator: StopLoadGeneratorFunction<T>;
stopLoadGeneratorIf: StopLoadGeneratorIfFunction<T>;
crashLoadGenerator: CrashLoadGeneratorFunction<T>;
crashLoadGeneratorIf: CrashLoadGeneratorIfFunction<T>;
}

export const errorsImpl = <J2, J1 extends JvmErrors<J2, any>, T extends Errors<T>>(
Expand Down Expand Up @@ -179,5 +241,26 @@ export const errorsImpl = <J2, J1 extends JvmErrors<J2, any>, T extends Errors<T
return wrap(jvmErrors.stopLoadGeneratorIf(message, condition));
}
}
},
crashLoadGenerator: (message: string | SessionTo<string>): T =>
wrap(
typeof message === "function"
? jvmErrors.crashLoadGenerator(underlyingSessionTo(message))
: jvmErrors.crashLoadGenerator(message)
),
crashLoadGeneratorIf: (message: string | SessionTo<string>, condition: string | SessionTo<boolean>): T => {
if (typeof message === "function") {
if (typeof condition === "function") {
return wrap(jvmErrors.crashLoadGeneratorIf(underlyingSessionTo(message), underlyingSessionTo(condition)));
} else {
return wrap(jvmErrors.crashLoadGeneratorIf(underlyingSessionTo(message), condition));
}
} else {
if (typeof condition === "function") {
return wrap(jvmErrors.crashLoadGeneratorIf(message, underlyingSessionTo(condition)));
} else {
return wrap(jvmErrors.crashLoadGeneratorIf(message, condition));
}
}
}
});
2 changes: 2 additions & 0 deletions js/core/src/structure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ export const exitHere = errorsImpl(JvmCoreDsl, wrapChainBuilder).exitHere;
export const exitHereIfFailed = errorsImpl(JvmCoreDsl, wrapChainBuilder).exitHereIfFailed;
export const stopLoadGenerator = errorsImpl(JvmCoreDsl, wrapChainBuilder).stopLoadGenerator;
export const stopLoadGeneratorIf = errorsImpl(JvmCoreDsl, wrapChainBuilder).stopLoadGeneratorIf;
export const crashLoadGenerator = errorsImpl(JvmCoreDsl, wrapChainBuilder).crashLoadGenerator;
export const crashLoadGeneratorIf = errorsImpl(JvmCoreDsl, wrapChainBuilder).crashLoadGeneratorIf;
2 changes: 1 addition & 1 deletion jvm/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Global / gatlingDevelopers := Seq(
val graalvmJdkVersion = "22.0.2"
val graalvmJsVersion = "24.0.2"
val coursierVersion = "2.1.10"
val gatlingVersion = "3.12.0-SNAPSHOT"
val gatlingVersion = "3.12.0"

// bit weird cause this is not a dependency of this project
val gatlingEnterpriseComponentPluginVersion = "1.9.6"
Expand Down

0 comments on commit 007b663

Please sign in to comment.