Skip to content

Commit

Permalink
version v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Sep 21, 2022
1 parent 2fe1a39 commit d4d9cb9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/NBomber/DomainServices/TestHost/TestHost.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type internal TestHost(dep: IGlobalDependency,
dep.ReportingSinks |> ReportingSinks.start _log

use cancelToken = new CancellationTokenSource()
schedulers |> TestHostConsole.LiveStatusTable.display cancelToken.Token isWarmUp
schedulers |> TestHostConsole.LiveStatusTable.display dep.ApplicationType cancelToken.Token isWarmUp

if reportingManager.IsSome then reportingManager.Value.Start()

Expand Down
120 changes: 65 additions & 55 deletions src/NBomber/DomainServices/TestHost/TestHostConsole.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open FSharp.Control.Reactive
open FsToolkit.ErrorHandling
open Spectre.Console

open NBomber.Contracts
open NBomber.Extensions.Data
open NBomber.Domain
open NBomber.Domain.DomainTypes
Expand All @@ -28,32 +29,35 @@ let displayStatus (msg: string) (runAction: StatusContext -> Task<'T>) =
status.StartAsync(msg, runAction)

let displayClientPoolProgress (dep: IGlobalDependency, consoleStatus: StatusContext, pool: ClientPool) =
pool.EventStream
|> Observable.takeWhile(function
| InitFinished -> false
| InitFailed -> false
| _ -> true
)
|> Observable.subscribe(function
| StartedInit (poolName, clientCount) ->
dep.Logger.Information("Start init client factory: {0}, client count: {1}", poolName, clientCount)

| StartedDispose poolName ->
dep.Logger.Information("Start disposing client factory: {0}", poolName)

| ClientInitialized (poolName,number) ->
consoleStatus.Status <- $"Initializing client factory: {Console.okColor poolName}, initialized client: {Console.blueColor number}"
consoleStatus.Refresh()

| ClientDisposed (poolName,number,error) ->
consoleStatus.Status <- $"Disposing client factory: {Console.okColor poolName}, disposed client: {Console.blueColor number}"
consoleStatus.Refresh()
error |> Option.iter(fun ex -> dep.Logger.Error(ex, "Client exception occurred"))

| InitFinished
| InitFailed -> ()
)
|> ignore

if dep.ApplicationType = ApplicationType.Console then

pool.EventStream
|> Observable.takeWhile(function
| InitFinished -> false
| InitFailed -> false
| _ -> true
)
|> Observable.subscribe(function
| StartedInit (poolName, clientCount) ->
dep.Logger.Information("Start init client factory: {0}, client count: {1}", poolName, clientCount)

| StartedDispose poolName ->
dep.Logger.Information("Start disposing client factory: {0}", poolName)

| ClientInitialized (poolName,number) ->
consoleStatus.Status <- $"Initializing client factory: {Console.okColor poolName}, initialized client: {Console.blueColor number}"
consoleStatus.Refresh()

| ClientDisposed (poolName,number,error) ->
consoleStatus.Status <- $"Disposing client factory: {Console.okColor poolName}, disposed client: {Console.blueColor number}"
consoleStatus.Refresh()
error |> Option.iter(fun ex -> dep.Logger.Error(ex, "Client exception occurred"))

| InitFinished
| InitFailed -> ()
)
|> ignore

let printContextInfo (dep: IGlobalDependency) =
dep.Logger.Verbose("NBomberConfig: {NBomberConfig}", $"%A{dep.NBomberConfig}")
Expand Down Expand Up @@ -113,41 +117,47 @@ module LiveStatusTable =
|> ignore
}

let display (cancelToken: CancellationToken) (isWarmUp: bool) (scnSchedulers: ScenarioScheduler list) =
let stopWatch = Stopwatch()
let mutable refreshTableCounter = 0
let display (appType: ApplicationType)
(cancelToken: CancellationToken)
(isWarmUp: bool)
(scnSchedulers: ScenarioScheduler list) =

let maxDuration =
if isWarmUp then scnSchedulers |> List.map(fun x -> x.Scenario) |> Scenario.getMaxWarmUpDuration
else scnSchedulers |> List.map(fun x -> x.Scenario) |> Scenario.getMaxDuration
if appType = ApplicationType.Console then

let table = buildTable ()
let stopWatch = Stopwatch()
let mutable refreshTableCounter = 0

let liveTable = AnsiConsole.Live(table)
liveTable.AutoClear <- false
liveTable.Overflow <- VerticalOverflow.Ellipsis
liveTable.Cropping <- VerticalOverflowCropping.Bottom
let maxDuration =
if isWarmUp then scnSchedulers |> List.map(fun x -> x.Scenario) |> Scenario.getMaxWarmUpDuration
else scnSchedulers |> List.map(fun x -> x.Scenario) |> Scenario.getMaxDuration

stopWatch.Start()
let table = buildTable ()

liveTable.StartAsync(fun ctx -> backgroundTask {
while not cancelToken.IsCancellationRequested do
try
let currentTime = stopWatch.Elapsed
if currentTime < maxDuration && refreshTableCounter = 0 then
let liveTable = AnsiConsole.Live(table)
liveTable.AutoClear <- false
liveTable.Overflow <- VerticalOverflow.Ellipsis
liveTable.Cropping <- VerticalOverflowCropping.Bottom

do! renderTable table scnSchedulers
stopWatch.Start()

table.Title <- TableTitle($"duration: ({currentTime:``hh\:mm\:ss``} - {maxDuration:``hh\:mm\:ss``})")
ctx.Refresh()
do! Task.Delay(1_000, cancelToken)
liveTable.StartAsync(fun ctx -> backgroundTask {
while not cancelToken.IsCancellationRequested do
try
let currentTime = stopWatch.Elapsed
if currentTime < maxDuration && refreshTableCounter = 0 then

refreshTableCounter <- refreshTableCounter + 1
if refreshTableCounter = 5 then refreshTableCounter <- 0
with
| _ -> ()
do! renderTable table scnSchedulers

table.Title <- TableTitle($"duration: ({maxDuration:``hh\:mm\:ss``} - {maxDuration:``hh\:mm\:ss``})")
ctx.Refresh()
})
|> ignore
table.Title <- TableTitle($"duration: ({currentTime:``hh\:mm\:ss``} - {maxDuration:``hh\:mm\:ss``})")
ctx.Refresh()
do! Task.Delay(1_000, cancelToken)

refreshTableCounter <- refreshTableCounter + 1
if refreshTableCounter = 5 then refreshTableCounter <- 0
with
| _ -> ()

table.Title <- TableTitle($"duration: ({maxDuration:``hh\:mm\:ss``} - {maxDuration:``hh\:mm\:ss``})")
ctx.Refresh()
})
|> ignore
10 changes: 2 additions & 8 deletions src/NBomber/NBomber.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Anton Moldovan</Authors>
<Company>NBomber</Company>
<Version>3.1.0</Version>
<Version>3.2.0</Version>
<Copyright>NBomber@2022</Copyright>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand All @@ -15,13 +15,7 @@
<Description>Modern and flexible load testing framework for Pull and Push scenarios, designed to test any system regardless a protocol (HTTP/WebSockets/AMQP etc) or a semantic model (Pull/Push).</Description>
<ServerGarbageCollection>true</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
<PackageReleaseNotes>- cosmetic changes for console progress bar
- changed default step timeout from 1 sec to 5 sec
- refactored scheduling scenarios to use one single timer
- added functionality to stop test execution when too many fails
- fixed minor console bug with rendering progress bar for warm up
- when it jumped before starting bombing
- fixed #480, added C# API Step.Create overload</PackageReleaseNotes>
<PackageReleaseNotes>- added live status update for console</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
Expand Down

0 comments on commit d4d9cb9

Please sign in to comment.