Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Jan 12, 2023
1 parent d512852 commit 14b6b47
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 141 deletions.
2 changes: 2 additions & 0 deletions tests/NBomber.IntegrationTests/HintsAnalyzerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ let ``HintsAnalyzer should be disabled by default`` () =
return Response.ok()
})
|> Scenario.withLoadSimulations [LoadSimulation.KeepConstant(1, seconds 1)]
|> Scenario.withoutWarmUp
|> NBomberRunner.registerScenario
|> NBomberRunner.runWithResult Seq.empty
|> Result.getOk
Expand All @@ -106,6 +107,7 @@ let ``disableHintsAnalyzer should disable hints`` () =
return Response.ok()
})
|> Scenario.withLoadSimulations [LoadSimulation.KeepConstant(1, seconds 1)]
|> Scenario.withoutWarmUp
|> NBomberRunner.registerScenario
|> NBomberRunner.enableHintsAnalyzer false
|> NBomberRunner.runWithResult Seq.empty
Expand Down
2 changes: 2 additions & 0 deletions tests/NBomber.IntegrationTests/LoggingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let ``set min logger level should work correctly`` () =
return Response.ok()
})
|> Scenario.withLoadSimulations [KeepConstant(1, TimeSpan.FromSeconds 3.0)]
|> Scenario.withoutWarmUp
|> NBomberRunner.registerScenario
|> NBomberRunner.withLoggerConfig createLoggerConfig1
|> NBomberRunner.run
Expand All @@ -46,6 +47,7 @@ let ``set min logger level should work correctly`` () =
return Response.ok()
})
|> Scenario.withLoadSimulations [KeepConstant(1, TimeSpan.FromSeconds 3.0)]
|> Scenario.withoutWarmUp
|> NBomberRunner.registerScenario
|> NBomberRunner.withLoggerConfig createLoggerConfig2
|> NBomberRunner.run
Expand Down
31 changes: 2 additions & 29 deletions tests/NBomber.IntegrationTests/NBomberRunnerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let ``withTargetScenarios should run only specified scenarios`` () =
})
|> Scenario.withInit(fun _ -> task { scn1Started <- true })
|> Scenario.withLoadSimulations [KeepConstant(1, seconds 1)]
|> Scenario.withoutWarmUp

let scn2 =
Scenario.create("scn_2", fun ctx -> task {
Expand All @@ -31,6 +32,7 @@ let ``withTargetScenarios should run only specified scenarios`` () =
})
|> Scenario.withInit(fun _ -> task { scn2Started <- true })
|> Scenario.withLoadSimulations [KeepConstant(1, seconds 1)]
|> Scenario.withoutWarmUp

NBomberRunner.registerScenarios [scn1; scn2]
|> NBomberRunner.withTargetScenarios ["scn_2"]
Expand All @@ -39,32 +41,3 @@ let ``withTargetScenarios should run only specified scenarios`` () =

test <@ scn1Started = false @>
test <@ scn2Started @>

// [<Fact>]
// let ``withDefaultStepTimeout should overrides default step timeout`` () =
//
// Scenario.create("timeout tests", fun ctx -> task {
//
// let! st = Step.run("step 1", ctx, fun () -> task {
// do! Task.Delay(milliseconds 100)
// return Response.ok()
// })
//
// let! st = Step.run("step 2", ctx, fun () -> task {
// do! Task.Delay(milliseconds 600)
// return Response.ok()
// })
//
// return Response.ok()
// })
// |> Scenario.withoutWarmUp
// |> Scenario.withLoadSimulations [KeepConstant(copies = 1, during = seconds 5)]
// |> NBomberRunner.registerScenario
// |> NBomberRunner.withoutReports
// |> NBomberRunner.withDefaultStepTimeout(milliseconds 500)
// |> NBomberRunner.run
// |> Result.getOk
// |> fun stats ->
// test <@ stats.ScenarioStats[0].GetStepStats("step 1").Fail.Request.Count = 0 @>
// test <@ stats.ScenarioStats[0].GetStepStats("step 2").Fail.Request.Count > 0 @>
// test <@ stats.ScenarioStats[0].GetStepStats("step 2").Fail.StatusCodes[0].StatusCode = Constants.TimeoutStatusCode @>
88 changes: 1 addition & 87 deletions tests/NBomber.IntegrationTests/Plugins/PluginTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,7 @@ let ``WorkerPlugin Init, Start, Stop should be invoked once for Warmup and once
test <@ List.rev invocationOrder = ["init"; "start"; "stop"; "start"; "stop"; "get_stats"; "get_hints"; "dispose"] @>

[<Fact>]
let ``StartTest should be invoked once`` () =

let scenarios = PluginTestHelper.createScenarios()
let mutable pluginStartTestInvokedCounter = 0

let plugin = {
new IWorkerPlugin with
member _.PluginName = "TestPlugin"
member _.Init(_, _) = Task.CompletedTask

member _.Start() =
pluginStartTestInvokedCounter <- pluginStartTestInvokedCounter + 1
Task.CompletedTask

member _.GetHints() = Array.empty
member _.GetStats(_) = Task.FromResult(new DataSet())
member _.Stop() = Task.CompletedTask
member _.Dispose() = ()
}

NBomberRunner.registerScenarios scenarios
|> NBomberRunner.withWorkerPlugins [plugin]
|> NBomberRunner.run
|> Result.mapError(fun x -> failwith x)
|> ignore

test <@ pluginStartTestInvokedCounter = 1 @>


[<Fact>]
let ``StartTest should be invoked with infra config`` () =
let ``Init should be invoked with infra config`` () =

let scenarios = PluginTestHelper.createScenarios()
let mutable pluginConfig = Unchecked.defaultof<_>
Expand Down Expand Up @@ -123,62 +93,6 @@ let ``StartTest should be invoked with infra config`` () =

test <@ isNull serilogConfig = false @>

[<Fact>]
let ``GetStats should be invoked only one time when final stats fetching`` () =

let scenarios = PluginTestHelper.createScenarios()
let mutable pluginGetStatsInvokedCounter = 0

let plugin = {
new IWorkerPlugin with
member _.PluginName = "TestPlugin"
member _.Init(_, _) = Task.CompletedTask
member _.Start() = Task.CompletedTask

member _.GetStats(stats) =
pluginGetStatsInvokedCounter <- pluginGetStatsInvokedCounter + 1
Task.FromResult(new DataSet())

member _.GetHints() = Array.empty
member _.Stop() = Task.CompletedTask
member _.Dispose() = ()
}

NBomberRunner.registerScenarios scenarios
|> NBomberRunner.withWorkerPlugins [plugin]
|> NBomberRunner.run
|> Result.mapError(fun x -> failwith x)
|> ignore

test <@ pluginGetStatsInvokedCounter = 1 @>

[<Fact>]
let ``StopTest should be invoked once`` () =

let scenarios = PluginTestHelper.createScenarios()
let mutable pluginFinishTestInvokedCounter = 0

let plugin = {
new IWorkerPlugin with
member _.PluginName = "TestPlugin"
member _.Init(_, _) = Task.CompletedTask
member _.Start() = Task.CompletedTask
member _.GetStats(_) = Task.FromResult(new DataSet())
member _.GetHints() = Array.empty
member _.Stop() =
pluginFinishTestInvokedCounter <- pluginFinishTestInvokedCounter + 1
Task.CompletedTask
member _.Dispose() = ()
}

NBomberRunner.registerScenarios scenarios
|> NBomberRunner.withWorkerPlugins [plugin]
|> NBomberRunner.run
|> Result.mapError(fun x -> failwith x)
|> ignore

test <@ pluginFinishTestInvokedCounter = 1 @>

[<Fact>]
let ``PluginStats should return empty data set in case of execution timeout`` () =
let inMemorySink = new InMemorySink()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,6 @@ let ``ReportingSink Init, Start, Stop should be invoked once for Warmup and once
|> Result.mapError failwith
|> ignore

test <@ saveRealtimeStatsCounter > 0 @>
test <@ List.rev invocationOrder = ["init"; "start"; "stop"; "start"; "stop"; "save_final_stats"; "dispose"] @>

25 changes: 1 addition & 24 deletions tests/NBomber.IntegrationTests/ScenarioTests/ValidationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let ``applyScenariosSettings() should override initial settings if the scenario
let duration1 = seconds 50

let scnName2 = "scenario_1"
let duration2 = seconds 5
let duration2 = seconds 80

let settings = {
ScenarioName = scnName1
Expand Down Expand Up @@ -106,26 +106,3 @@ let ``ScenarioSettings should be validated on duplicates `` () =
|> NBomberRunner.run
|> Result.getError
|> fun error -> test <@ error.Contains("Scenario names are not unique in JSON config") @>

// [<Fact>]
// let ``withStepTimeout should set step timeout`` () =
//
// let step1 = Step.create("step_1", timeout = seconds 2, execute = fun context -> task {
// do! Task.Delay(seconds 4)
// return Response.ok()
// })
//
// Scenario.create "1" [step1]
// |> Scenario.withoutWarmUp
// |> Scenario.withLoadSimulations [KeepConstant(1, seconds 10)]
// |> NBomberRunner.registerScenario
// |> NBomberRunner.withoutReports
// |> NBomberRunner.run
// |> Result.getOk
// |> NodeStats.getScenarioStats "1"
// |> ScenarioStats.getStepStats "step_1"
// |> fun stepsStats ->
// test <@ stepsStats.Ok.Request.Count = 0 @>
// 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 @>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let ``Warmup should have no effect on stats`` () =

return Response.ok()
})
|> Scenario.withWarmUpDuration(seconds 3)
|> Scenario.withWarmUpDuration(seconds 1)
|> Scenario.withLoadSimulations [KeepConstant(copies = 1, during = seconds 1)]
|> NBomberRunner.registerScenario
|> NBomberRunner.withoutReports
Expand Down

0 comments on commit 14b6b47

Please sign in to comment.