View Source Chaperon.Scenario (chaperon v0.3.1)
Helper module to be used by scenario definition modules.
Imports Chaperon.Session
and other helper modules for easy scenario
definitions.
example
Example
defmodule MyScenario do
use Chaperon.Scenario
def init(session) do
# Possibly do something with session before running scenario
delay = :rand.uniform
if delay > 0.5 do
{:ok, session |> with_delay(delay |> seconds)}
else
{:ok, session}
end
end
def run(session) do
session
|> post("/api/messages", json: %{message: "what's up?"})
|> get("/api/messages")
end
def with_delay(session, delay) do
put_in session.config[:delay], delay
end
end
Link to this section Summary
Functions
Runs a given scenario module with a given config and returns the scenario's
session annotated with histogram metrics via the Chaperon.Scenario.Metrics
module. The returned Chaperon.Session
will include histogram data for all
performed Chaperon.Actionable
s, including for all run actions run
asynchronously as part of the scenario.
Initializes a Chaperon.Scenario
for a given session
.
Returns the name of a Chaperon.Scenario
based on the module
its referring
to.
Cleans up any resources after the Scenario was run (if needed). Can be overriden.
Link to this section Types
@type t() :: %Chaperon.Scenario{module: module()}
Link to this section Functions
@spec execute(module(), map()) :: Chaperon.Session.t()
Runs a given scenario module with a given config and returns the scenario's
session annotated with histogram metrics via the Chaperon.Scenario.Metrics
module. The returned Chaperon.Session
will include histogram data for all
performed Chaperon.Actionable
s, including for all run actions run
asynchronously as part of the scenario.
@spec execute_nested(t(), Chaperon.Session.t(), map()) :: Chaperon.Session.t()
@spec init(module(), Chaperon.Session.t()) :: {:ok, Chaperon.Session.t()}
Initializes a Chaperon.Scenario
for a given session
.
If scenario_mod
defines an init/1
callback function, calls it with
session
and returns its return value.
Otherwise defaults to returning {:ok, session}
.
@spec initial_delay(Chaperon.Session.t()) :: Chaperon.Session.t()
Returns the name of a Chaperon.Scenario
based on the module
its referring
to.
example
Example
iex> alias Chaperon.Scenario
iex> Scenario.name %Scenario{module: Scenarios.Bruteforce.Login}
"Scenarios.Bruteforce.Login"
@spec nested_session(t(), Chaperon.Session.t(), map()) :: Chaperon.Session.t()
@spec new_session(t(), map()) :: Chaperon.Session.t()
@spec run( t(), Chaperon.Session.t() | {:ok, Chaperon.Session.t()} | {:error, any()} ) :: Chaperon.Session.t() | {:error, any()}
@spec teardown(t(), Chaperon.Session.t()) :: Chaperon.Session.t()
Cleans up any resources after the Scenario was run (if needed). Can be overriden.
If scenario
's implementation module defines a teardown/1
callback function,
calls it with session
to clean up resources as needed.
Returns the given session afterwards.