diff --git a/docs/source/api.rst b/docs/source/api.rst index 36529b4..87a565f 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -8,7 +8,7 @@ This section provides detailed documentation of the Stressify.jl API. Functions --------- -.. function:: options(; vus::Int=1, format::String="default", ramp_duration::Union{Float64, Nothing}=nothing, max_vus::Union{Int, Nothing}=nothing, iterations::Union{Int, Nothing}=nothing, duration::Union{Float64, Nothing}=nothing) +.. function:: options(; vus::Int=1, format::String="default", ramp_duration::Union{Float64, Nothing}=nothing, max_vus::Union{Int, Nothing}=nothing, iterations::Union{Int, Nothing}=nothing, duration::Union{Float64, Nothing}=nothing, noDebug::Bool=false) Determine the test configuration options, such as the number of virtual users (VUs), format, ramp duration, maximum VUs, iterations, and duration. @@ -18,6 +18,7 @@ Functions :param max_vus: The maximum number of virtual users to simulate. :param iterations: The number of iterations to run. Don`t use with format "vus-ramping". :param duration: The duration of the test in seconds. + :param noDebug: Disable debug mode. .. function:: run_test(requests::Vararg{NamedTuple} diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 1b6dd27..a6d1a3c 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -142,6 +142,23 @@ Available Examples **Purpose**: Ideal for API testing and check the return from endpoint are you testing. +9. **NinehtTest.jl** + - **Description**: Example of how to use Stressify to create tests and remove all Debugs in the code. + + **Key Features**: + + - Loads API endpoints. + - Monitors basic performance metrics. + - Remove all debugs in the code. + + **How to Run**: + Execute the following command: + ``` + julia examples/eightTest.jl + ``` + + **Purpose**: Ideal to running the test in pipeline wihtout debugs. + How to run the examples? ------------------------ diff --git a/examples/ninethTest.jl b/examples/ninethTest.jl new file mode 100644 index 0000000..b3a3c69 --- /dev/null +++ b/examples/ninethTest.jl @@ -0,0 +1,15 @@ +import Pkg +Pkg.activate(".") +using Stressify + +#execute for the one VU for one iteration +Stressify.options( + vus = 2, + iterations = 10, + duration = nothing, + noDebug = true +) + +results = Stressify.run_test( + Stressify.http_get("https://httpbin.org/get"), +) diff --git a/examples/reports/grafico.png b/examples/reports/grafico.png index 25dd90d..e27ba1c 100644 Binary files a/examples/reports/grafico.png and b/examples/reports/grafico.png differ diff --git a/examples/reports/report.json b/examples/reports/report.json index e96e2f8..7fef74b 100644 --- a/examples/reports/report.json +++ b/examples/reports/report.json @@ -1 +1 @@ -{"success_rate":100.0,"iterations":15,"vus":2,"tps":1.1658461953946686,"median_time":0.900367375,"p95_time":5.780789125,"p99_time":5.780789125,"error_rate":0.0,"errors":0,"p90_time":2.959136208,"std_time":1.5039213841402637,"mean_time":1.2795243971999999,"all_times":[5.780789125,0.900367375,0.324176875,1.764315958,0.146059709,1.066745125,2.050738709,0.324932083,1.625065625,1.222245667,0.146095292,0.144808708,0.144212791,0.593176708,2.959136208],"max_time":5.780789125,"min_time":0.144212791,"rps":1.1658461953946686} \ No newline at end of file +{"success_rate":100.0,"iterations":20,"vus":2,"tps":2.4815394889984774,"median_time":0.179957896,"p95_time":1.50496525,"p99_time":4.911083292,"error_rate":0.0,"errors":0,"p90_time":1.195147875,"std_time":1.0761258081666814,"mean_time":0.6085428021499999,"all_times":[4.911083292,0.172388959,0.175675083,0.171129125,0.1704415,0.4170255,0.167570041,0.17593975,1.195147875,0.33855725,1.50496525,0.172773042,0.183976042,0.170094875,0.36845525,0.630870625,0.168413667,0.170359417,0.588411333,0.317578167],"max_time":4.911083292,"min_time":0.167570041,"rps":2.4815394889984774} \ No newline at end of file diff --git a/src/core.jl b/src/core.jl index c8425fa..3618c1f 100644 --- a/src/core.jl +++ b/src/core.jl @@ -26,19 +26,31 @@ Configura opções globais para os testes de performance. """ function options(; vus::Int = 1, format::String = "default", max_vus::Union{Int, Nothing} = nothing, ramp_duration::Union{Float64, Nothing} = nothing, iterations::Union{Int, Nothing} = nothing, - duration::Union{Float64, Nothing} = nothing) + duration::Union{Float64, Nothing} = nothing, noDebug::Bool = false) GLOBAL_OPTIONS[:vus] = vus GLOBAL_OPTIONS[:format] = format GLOBAL_OPTIONS[:max_vus] = max_vus GLOBAL_OPTIONS[:ramp_duration] = ramp_duration GLOBAL_OPTIONS[:iterations] = iterations GLOBAL_OPTIONS[:duration] = duration + GLOBAL_OPTIONS[:noDebug] = noDebug if format == "vus-ramping" && (max_vus === nothing || duration === nothing || ramp_duration === nothing) error("Para o formato 'vus-ramping', você deve especificar 'max_vus', 'ramp_duration' e 'duration'.") end end +""" + debug_log(msg::String) + +Loga mensagens de depuração apenas se a opção `noDebug` estiver desativada. +""" +function debug_log(msg::String) + if !get(GLOBAL_OPTIONS, :noDebug, false) + println(msg) + end +end + """ check(response, method::String, checks::Vector{Check}) @@ -53,14 +65,14 @@ function check(response, method::String, checks::Vector{Check}) try if chk.condition(response) push!(CHECK_RESULTS[], "✔️ $(method) - $(chk.description) - Success") - println("✔️ $(method) - $(chk.description) - Success") + debug_log("✔️ $(method) - $(chk.description) - Success") else push!(CHECK_RESULTS[], "❌ $(method) - $(chk.description) - Failed") - println("❌ $(method) - $(chk.description) - Failed") + debug_log("❌ $(method) - $(chk.description) - Failed") end catch e push!(CHECK_RESULTS[], "⚠️ $(method) - $(chk.description) - Error: $e") - println("⚠️ $(method) - $(chk.description) - Error: $e") + debug_log("⚠️ $(method) - $(chk.description) - Error: $e") end end end @@ -276,7 +288,7 @@ function run_test(requests::Vararg{NamedTuple}) sleep(interval) current_vus = new_vu atomic_add!(active_vus, 1) - println("Ramp-up: Incrementando VUs para $current_vus") + debug_log("Ramp-up: Incrementando VUs para $current_vus") push!(tasks, spawn_vu_task( new_vu, @@ -289,7 +301,7 @@ function run_test(requests::Vararg{NamedTuple}) )) end - println("Ramp-up concluído. Total de VUs ativos: $(active_vus[])") + debug_log("Ramp-up concluído. Total de VUs ativos: $(active_vus[])") end # Aguarda o término do ramp-up @@ -337,7 +349,7 @@ end function spawn_vu_task(vu_id, start_time, duration, iterations, requests, local_results, total_errors) return Threads.@spawn begin - println("Thread $vu_id inicializada.") + debug_log("Thread $vu_id inicializada.") request_idx = 1 iteration_count = 0 @@ -361,7 +373,7 @@ function spawn_vu_task(vu_id, start_time, duration, iterations, requests, local_ iteration_count += 1 method_name = string(requests[request_idx].method) |> x -> split(x, ".")[end] - println("Requisição (Método: $method_name) finalizada no thread $vu_id (Tempo: $elapsed_time segundos)") + debug_log("Requisição (Método: $method_name) finalizada no thread $vu_id (Tempo: $elapsed_time segundos)") catch e atomic_add!(total_errors, 1) println("Erro na requisição no thread $vu_id: ", e) @@ -370,7 +382,7 @@ function spawn_vu_task(vu_id, start_time, duration, iterations, requests, local_ request_idx = (request_idx % length(requests)) + 1 end - println("Thread $vu_id finalizada após $iteration_count iterações.") + debug_log("Thread $vu_id finalizada após $iteration_count iterações.") end end diff --git a/test/test_core.jl b/test/test_core.jl index 9b13177..f5a85e3 100644 --- a/test/test_core.jl +++ b/test/test_core.jl @@ -171,6 +171,7 @@ end @test_throws ErrorException Stressify.options(format = "vus-ramping", max_vus = nothing, ramp_duration = 5.0, duration = 60.0) @test_throws ErrorException Stressify.options(format = "vus-ramping", max_vus = 50, ramp_duration = nothing, duration = 60.0) @test_throws ErrorException Stressify.options(format = "vus-ramping", max_vus = 50, ramp_duration = 5.0, duration = nothing) + Stressify.options(vus = 4, format = "vus-ramping", max_vus = 4, ramp_duration = 5.0, iterations = nothing, duration = 60.0, noDebug = true) Stressify.options(format="default", max_vus=nothing, ramp_duration=nothing, duration=nothing)