Skip to content

Commit

Permalink
Merge pull request #56 from jfilhoGN/26-create-a-params-to-view-or-no…
Browse files Browse the repository at this point in the history
…t-println-about-threads-and-execution

create params in options to remove all debugs in code
  • Loading branch information
jfilhoGN authored Dec 11, 2024
2 parents b05760b + 0ab7ac8 commit 9470b23
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 11 deletions.
3 changes: 2 additions & 1 deletion docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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}

Expand Down
17 changes: 17 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
------------------------
Expand Down
15 changes: 15 additions & 0 deletions examples/ninethTest.jl
Original file line number Diff line number Diff line change
@@ -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"),
)
Binary file modified examples/reports/grafico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/reports/report.json
Original file line number Diff line number Diff line change
@@ -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}
{"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}
30 changes: 21 additions & 9 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand 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

Expand All @@ -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)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/test_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 9470b23

Please sign in to comment.