diff --git a/examples/FSharpDev/HttpTests/SimpleHttpTest.fs b/examples/FSharpDev/HttpTests/SimpleHttpTest.fs index e4cda5f6..adb47157 100644 --- a/examples/FSharpDev/HttpTests/SimpleHttpTest.fs +++ b/examples/FSharpDev/HttpTests/SimpleHttpTest.fs @@ -3,7 +3,6 @@ module FSharpDev.HttpTests.SimpleHttpTest open System.Net.Http open NBomber open NBomber.Contracts -open NBomber.Contracts.Thresholds open NBomber.FSharp let run () = @@ -42,10 +41,6 @@ let run () = data_transfer_all_bytes (fun x -> x < 10000) } ) -// |> Scenario.withThresholds [ -// RequestAllCount((fun x -> x > 1290), Some "request all count > 290") -// RequestOkCount((fun x -> x > 180), None) -// ] |> NBomberRunner.registerScenario |> NBomberRunner.run |> ignore diff --git a/src/NBomber/Api/FSharp.fs b/src/NBomber/Api/FSharp.fs index ee88fcba..6034c658 100644 --- a/src/NBomber/Api/FSharp.fs +++ b/src/NBomber/Api/FSharp.fs @@ -455,6 +455,38 @@ type ThresholdsBuilder () = member _.DataTransferAllBytes(state, predicate, ?description: string) = state @ [ DataTransferAllBytes(predicate, description) ] + [] + member _.DataTransferMaxBytes(state, predicate, ?description: string) = + state @ [ DataTransferMaxBytes(predicate, description) ] + + [] + member _.DataTransferMinBytes(state, predicate, ?description: string) = + state @ [ DataTransferMinBytes(predicate, description) ] + + [] + member _.DataTransferMeanBytes(state, predicate, ?description: string) = + state @ [ DataTransferMeanBytes(predicate, description) ] + + [] + member _.DataTransferStdDev(state, predicate, ?description: string) = + state @ [ DataTransferStdDev(predicate, description) ] + + [] + member _.DataTransferPercent50(state, predicate, ?description: string) = + state @ [ DataTransferPercent50(predicate, description) ] + + [] + member _.DataTransferPercent75(state, predicate, ?description: string) = + state @ [ DataTransferPercent75(predicate, description) ] + + [] + member _.DataTransferPercent95(state, predicate, ?description: string) = + state @ [ DataTransferPercent95(predicate, description) ] + + [] + member _.DataTransferPercent99(state, predicate, ?description: string) = + state @ [ DataTransferPercent99(predicate, description) ] + [] module ComputationExpressions = diff --git a/tests/NBomber.IntegrationTests/ScenarioTests.fs b/tests/NBomber.IntegrationTests/ScenarioTests.fs index b916d912..0b774087 100644 --- a/tests/NBomber.IntegrationTests/ScenarioTests.fs +++ b/tests/NBomber.IntegrationTests/ScenarioTests.fs @@ -379,3 +379,94 @@ let ``withStepTimeout should set step timeout`` () = test <@ stepsStats.Fail.Request.Count > 0 @> test <@ stepsStats.Fail.StatusCodes[0].StatusCode = NBomber.Constants.TimeoutStatusCode @> test <@ stepsStats.Fail.StatusCodes[0].Count = stepsStats.Fail.Request.Count @> + +[] +let ``withThresholds should result in EmptyThresholds error if empty`` () = + + let step1 = Step.create("step_1", fun _ -> task { + do! Task.Delay(milliseconds 10) + return Response.ok() + }) + + let scenarioName = "1" + + Scenario.create scenarioName [ step1 ] + |> Scenario.withoutWarmUp + |> Scenario.withLoadSimulations [KeepConstant(1, seconds 2)] + |> Scenario.withThresholds [ ] + |> NBomberRunner.registerScenario + |> NBomberRunner.run + |> Result.getError + |> fun error -> test <@ error.Contains($"Scenario: '{scenarioName}' has no thresholds") @> + +[] +let ``withThresholds should set ThresholdStats with respect to overriden description`` () = + + let step1 = Step.create("step_1", timeout = seconds 2, execute = fun _ -> task { + do! Task.Delay(seconds 4) + return Response.ok() + }) + + let alwaysTrue _ = true + let shouldContain description stats = + stats |> Array.exists (fun stat -> stat.Threshold.Description = description) + + Scenario.create "1" [step1] + |> Scenario.withoutWarmUp + |> Scenario.withLoadSimulations [KeepConstant(1, seconds 10)] + |> Scenario.withThresholds ( + thresholds { + request_all_count alwaysTrue "request all count > 0" + request_ok_count alwaysTrue + request_failed_count alwaysTrue + request_failed_rate alwaysTrue + rps alwaysTrue "requests per second should be > 5" + latency_min alwaysTrue + latency_mean alwaysTrue + latency_max alwaysTrue + latency_std_dev alwaysTrue "latency standard deviation > 50 and < 100" + latency_p50 alwaysTrue + latency_p75 alwaysTrue + latency_p95 alwaysTrue + latency_p99 alwaysTrue + data_transfer_all_bytes alwaysTrue + data_transfer_max_bytes alwaysTrue + data_transfer_min_bytes alwaysTrue + data_transfer_mean_bytes alwaysTrue + data_transfer_stf_dev alwaysTrue + data_transfer_p50 alwaysTrue + data_transfer_p75 alwaysTrue + data_transfer_p95 alwaysTrue + data_transfer_p99 alwaysTrue + } + ) + |> NBomberRunner.registerScenario + |> NBomberRunner.run + |> Result.getOk + |> NodeStats.getScenarioStats "1" + |> fun scenarioStats -> scenarioStats.ThresholdStats.Value + |> fun thresholdStats -> + test <@ thresholdStats |> Array.length = 22 @> + test <@ thresholdStats |> Array.forall (fun stats -> stats.Status = Passed) @> + test <@ thresholdStats |> shouldContain "request all count > 0" @> + test <@ thresholdStats |> shouldContain "request count - ok" @> + test <@ thresholdStats |> shouldContain "request count - failed" @> + test <@ thresholdStats |> shouldContain "request rate - failed" @> + test <@ thresholdStats |> shouldContain "requests per second should be > 5" @> + test <@ thresholdStats |> shouldContain "latency - min" @> + test <@ thresholdStats |> shouldContain "latency - mean" @> + test <@ thresholdStats |> shouldContain "latency - max" @> + test <@ thresholdStats |> shouldContain "latency standard deviation > 50 and < 100" @> + test <@ thresholdStats |> shouldContain "latency percentile - 50%" @> + test <@ thresholdStats |> shouldContain "latency percentile - 75%" @> + test <@ thresholdStats |> shouldContain "latency percentile - 95%" @> + test <@ thresholdStats |> shouldContain "latency percentile - 99%" @> + test <@ thresholdStats |> shouldContain "data transfer bytes - min" @> + test <@ thresholdStats |> shouldContain "data transfer bytes - mean" @> + test <@ thresholdStats |> shouldContain "data transfer bytes - max" @> + test <@ thresholdStats |> shouldContain "data transfer bytes - all" @> + test <@ thresholdStats |> shouldContain "data transfer - StdDev" @> + test <@ thresholdStats |> shouldContain "data transfer percentile - 50%" @> + test <@ thresholdStats |> shouldContain "data transfer percentile - 75%" @> + test <@ thresholdStats |> shouldContain "data transfer percentile - 95%" @> + test <@ thresholdStats |> shouldContain "data transfer percentile - 99%" @>