Interface PerfHook
Implementations receive HTTP request timing events and can report them to external performance testing frameworks.
The event lifecycle:
getPerfEventName(io.karatelabs.http.HttpRequest, io.karatelabs.core.ScenarioRuntime)is called before HTTP request to get the name- HTTP request executes with timing captured
reportPerfEvent(io.karatelabs.core.PerfEvent)is called with the completed event
Events are "held" until the next HTTP request or scenario end, so that assertion failures after an HTTP request can be attributed to that request.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidafterFeature(FeatureResult result) Called after a feature completes execution.getPerfEventName(HttpRequest request, ScenarioRuntime runtime) Get the name for a performance event based on the HTTP request.default voidPause execution for the specified duration.voidreportPerfEvent(PerfEvent event) Report a completed performance event.default voidSubmit a task for execution in the performance framework's execution model.
-
Method Details
-
getPerfEventName
Get the name for a performance event based on the HTTP request.This is called before the request executes. The implementation can use URI patterns or custom logic to determine the name that will appear in performance reports.
- Parameters:
request- the HTTP request about to be executedruntime- the scenario runtime context- Returns:
- the name for this request in performance reports, or null to skip reporting
-
reportPerfEvent
Report a completed performance event.Called after HTTP request completion (possibly with failure info added later). The event includes timing, status code, and any failure message.
- Parameters:
event- the completed performance event
-
submit
Submit a task for execution in the performance framework's execution model.For Gatling, this ensures tasks run within Gatling's scheduler. Default implementation runs synchronously.
- Parameters:
task- the task to execute
-
afterFeature
Called after a feature completes execution.Allows the performance framework to perform cleanup or final reporting.
- Parameters:
result- the feature execution result
-
pause
Pause execution for the specified duration.For Gatling integration, this uses Gatling's non-blocking pause mechanism rather than Thread.sleep(), which is important for virtual user scaling.
- Parameters:
millis- the pause duration in milliseconds
-