Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions examples/FSharpDev/HttpTests/SimpleHttpTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down Expand Up @@ -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
32 changes: 32 additions & 0 deletions src/NBomber/Api/FSharp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,38 @@ type ThresholdsBuilder () =
member _.DataTransferAllBytes(state, predicate, ?description: string) =
state @ [ DataTransferAllBytes(predicate, description) ]

[<CustomOperation("data_transfer_max_bytes")>]
member _.DataTransferMaxBytes(state, predicate, ?description: string) =
state @ [ DataTransferMaxBytes(predicate, description) ]

[<CustomOperation("data_transfer_min_bytes")>]
member _.DataTransferMinBytes(state, predicate, ?description: string) =
state @ [ DataTransferMinBytes(predicate, description) ]

[<CustomOperation("data_transfer_mean_bytes")>]
member _.DataTransferMeanBytes(state, predicate, ?description: string) =
state @ [ DataTransferMeanBytes(predicate, description) ]

[<CustomOperation("data_transfer_stf_dev")>]
member _.DataTransferStdDev(state, predicate, ?description: string) =
state @ [ DataTransferStdDev(predicate, description) ]

[<CustomOperation("data_transfer_p50")>]
member _.DataTransferPercent50(state, predicate, ?description: string) =
state @ [ DataTransferPercent50(predicate, description) ]

[<CustomOperation("data_transfer_p75")>]
member _.DataTransferPercent75(state, predicate, ?description: string) =
state @ [ DataTransferPercent75(predicate, description) ]

[<CustomOperation("data_transfer_p95")>]
member _.DataTransferPercent95(state, predicate, ?description: string) =
state @ [ DataTransferPercent95(predicate, description) ]

[<CustomOperation("data_transfer_p99")>]
member _.DataTransferPercent99(state, predicate, ?description: string) =
state @ [ DataTransferPercent99(predicate, description) ]

[<AutoOpen>]
module ComputationExpressions =

Expand Down
91 changes: 91 additions & 0 deletions tests/NBomber.IntegrationTests/ScenarioTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 @>

[<Fact>]
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") @>

[<Fact>]
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%" @>