Skip to content

Commit

Permalink
Merge pull request #212 from ddosify/feat/add-p98
Browse files Browse the repository at this point in the history
add p98 func
  • Loading branch information
fatihbaltaci authored Jul 3, 2023
2 parents 921085a + 5b6b192 commit d249eb1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/scenario/scripting/assertion/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,13 @@ func TestAssert(t *testing.T) {
},
expected: true,
},
{
input: "p98(iteration_duration) == 99",
envs: &evaluator.AssertEnv{
TotalTime: []int64{34, 37, 39, 44, 45, 55, 66, 67, 72, 75, 77, 89, 92, 98, 99},
},
expected: true,
},
{
input: "p95(iteration_duration) == 99",
envs: &evaluator.AssertEnv{
Expand Down Expand Up @@ -792,6 +799,11 @@ func TestAssert(t *testing.T) {
expected: false,
expectedError: "ArgumentError",
},
{
input: "p98(23)", // arg must be array
expected: false,
expectedError: "ArgumentError",
},
{
input: "p95(23)", // arg must be array
expected: false,
Expand Down
9 changes: 9 additions & 0 deletions core/scenario/scripting/assertion/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ func Eval(node ast.Node, env *AssertEnv, receivedMap map[string]interface{}) (in
}
}
return percentile(arr, 99)
case P98:
arr, ok := args[0].([]int64)
if !ok {
return false, ArgumentError{
msg: "argument of percentile funcs must be an int64 array",
wrappedErr: nil,
}
}
return percentile(arr, 98)
case P95:
arr, ok := args[0].([]int64)
if !ok {
Expand Down
2 changes: 2 additions & 0 deletions core/scenario/scripting/assertion/evaluator/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ var assertionFuncMap = map[string]struct{}{
MAX: {},
AVG: {},
P99: {},
P98: {},
P95: {},
P90: {},
P80: {},
Expand All @@ -227,6 +228,7 @@ const (
MAX = "max"
AVG = "avg"
P99 = "p99"
P98 = "p98"
P95 = "p95"
P90 = "p90"
P80 = "p80"
Expand Down
1 change: 1 addition & 0 deletions engine_docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ Unlike assertions focused on individual steps, which determine the success or fa
| Function | Parameters | Description |
| ---------- | ---------------------- | ------------------------------------------------- |
| `p99` | ( arr `int array` ) | 99th percentile, use as `p99(iteration_duration)` |
| `p98` | ( arr `int array` ) | 98th percentile, use as `p98(iteration_duration)` |
| `p95` | ( arr `int array`) | 95th percentile, use as `p95(iteration_duration)` |
| `p90` | ( arr `int array`) | 90th percentile, use as `p90(iteration_duration)` |
| `p80` | ( arr `int array`) | 80th percentile, use as `p80(iteration_duration)` |
Expand Down

0 comments on commit d249eb1

Please sign in to comment.