chaperon v0.3.1 Chaperon.Session View Source
Defines a Session struct and corresponding helper functions that are used
within Chaperon.Scenario
definitions.
Most of Chaperon's logic is centered around these sessions.
Link to this section Summary
Functions
Awaits a given async task within session
.
Wraps a function call with session
as an arg in a call to
Chaperon.Session.call_traced
and captures function call duration metrics in
session
.
Adds a given Task
to session
under a given name
.
Stores a Chaperon.Session.Error
in session
for a given action
for later
inspection.
Stores a given metric val
under a given name
in session
.
Adds a given HTTP request result
to session
for the given action
.
Adds a given WebSocket action result
to session
for a given action
.
Assigns a given list of key-value pairs (as a Keyword
list) in session
for further usage later.
Assigns a given list of key-value pairs (as a Keyword
list) under a given
namespace in session
for further usage later.
Runs a given function with args asynchronously from session
.
Returns a single task or a list of tasks associated with a given task_name
in session
.
Await all async tasks for the given task_names
in session
.
Await all async tasks with a given task_name
in session
.
Await a given signal in the current session and returns session afterwards.
Await an expected signal with a given timeout.
Await any incoming signal for current session within given timeout. If callback is provided, it will be called with the session and the received signal value.
Calls a function inside the session
's scenario module with the given name
and args, returning the resulting session.
Calls a callback
with session
and an additional argument.
Calls a given function or a function with the given name and args, then
captures duration metrics in session
.
Concurrently spreads a given action with a given rate over a given time
interval within session
.
Concurrently spreads a given action with a given rate over a given time
interval within session
.
Get a (possibly nested) config value.
Get a (possibly nested) config value and return the given default value, if config value does not exist.
Delays further execution of session
by a given duration
.
duration
can also be {:random, integer_val}
in which case random_delay
is called with integer_val
.
Performs a HTTP DELETE request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
Deletes all cookies from session
's cookie store.
Returns a Chaperon.Session.Error
for the given session
and with a given
reason
.
Returns a Chaperon.Session.Error
for the given session
and with a given
reason
for a given action
.
Performs a HTTP GET request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
Loops a given action for a given duration, returning the resulting session at the end.
Merges two session's results & metrics and returns the resulting session.
Merges errors of two sessions.
Merges metrics of two sessions.
Merges results of two sessions.
Returns the session
s configured name or scenario's module name.
Returns {:ok, reason}
.
Performs a HTTP PATCH request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
Performs a HTTP POST request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
Performs a HTTP PUT request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
Delays further execution of session
by a random value up to the given
duration
.
Removes a Task
with a given task_name
from session
.
Repeats calling a given function with session a given amount of times, returning the resulting session at the end.
Repeats calling a given function with session and additional args a given amount of times, returning the resulting session at the end.
Repeats calling a given function with session a given amount of times, returning the resulting session at the end. Also traces durations for all calls to the given function.
Repeats calling a given function with session and additional args a given amount of times, returning the resulting session at the end.
Call a given function (with arguments). If any exception is raised, retry the call a given amount of times (defaults to 1 retry). The retry can be delayed by a fixed or random duration (defaults to 1s).
Runs a given action within session
and returns the resulting
session.
Runs a potentially configured callback for a given action in case of success.
In case of failure, runs the configured error callback with an
{:error, reason}
tuple.
Runs & captures metrics of running another Chaperon.Scenario
from session
using session
s config.
Runs & captures metrics of running another Chaperon.Scenario
from session
with a given config
.
Runs & captures metrics of running another Chaperon.Scenario
from session
with a given config
on a random node in the Chaperon cluster.
Runs & captures metrics of running another Chaperon.Scenario
from session
with a given config
.
Returns session
's errors wrapped with session
's name.
Returns session
's metrics wrapped with session
's name.
Returns session
's results wrapped with session
's name.
Updates a session's config based on a given Keyword list of new values to be
used for config
in session
.
Updates a session's config based on a given Keyword list of new values inside
a given namespace to be used for config
in session
.
Send a signal to the current session's async task with the given name.
Sends a signal to the current session's parent session (that spawned it via
a call to Session.async
).
Stores HTTP response cookies in session
cookie store for further outgoing
requests.
Records a custom metric for the duration of calling a given function with the
current Chaperon.Session
.
Records a custom metric for the duration of calling a given function with the
current Chaperon.Session
.
Returns the session's configured timeout or the default timeout, if none specified.
Updates assignments based on a given Keyword list of functions to be used for
updating assigned
in session
.
Updates assignments based on a given Keyword list of functions to be used for
updating assigned
within namespace
in session
.
Updates a session's config based on a given Keyword list of functions to be
used for updating config
in session
.
Updates a session's config based on a given Keyword list of functions to be
used for updating config
in session
under a given namespace.
Performs a WebSocket message receive on session
s WebSocket connection.
Takes an optional list of options
to be passed along to Socket.Web.recv/2
.
Closes the session's websocket connection.
Takes an optional list of options
to be passed along to Socket.Web.close/2
.
Performs a WebSocket connection attempt on session
's base_url and
path
.
Performs a WebSocket message receive on session
s WebSocket connection.
Takes an optional list of options
to be passed along to Socket.Web.recv/2
.
Performs a WebSocket message send on session
s WebSocket connection.
Takes an optional list of options
to be passed along to Socket.Web.send/3
.
Makes a given function call async for session
.
Link to this section Types
cc_spread_options()
View Sourcecc_spread_options() :: [ rate: Chaperon.Action.SpreadAsync.rate(), interval: Chaperon.Action.SpreadAsync.time(), name: atom() | nil ] | %{ rate: Chaperon.Action.SpreadAsync.rate(), interval: Chaperon.Action.SpreadAsync.time(), name: atom() | nil }
result_callback()
View Sourceresult_callback() :: atom() | (Chaperon.Session.t(), any() -> Chaperon.Session.t())
retry_options()
View Sourceretry_options() :: [ retries: non_neg_integer(), delay: non_neg_integer(), random_delay: non_neg_integer() ]
t()
View Sourcet() :: %Chaperon.Session{ assigned: map(), async_tasks: map(), cancellation: String.t() | nil, config: map(), cookies: [String.t()], errors: map(), id: String.t(), interval_task: Task.t() | nil, metrics: map(), name: String.t(), parent_id: String.t() | nil, parent_pid: pid() | nil, results: map(), scenario: Chaperon.Scenario.t(), timeout_at: DateTime.t() | nil }
Link to this section Functions
Awaits a given async task within session
.
Example
session
<~ foo
<~ bar
Is the same as:
session
|> await(:foo)
|> await(:bar)
Wraps a function call with session
as an arg in a call to
Chaperon.Session.call_traced
and captures function call duration metrics in
session
.
Example
session
>>> foo
>>> bar(1,2,3)
Is the same as:
session
|> call_traced(:foo)
|> call_traced(:bar, [1,2,3])
abort(session, reason)
View Sourceabort(Chaperon.Session.t(), String.t()) :: Chaperon.Session.t()
add_async_task(session, name, task)
View Sourceadd_async_task(Chaperon.Session.t(), atom(), Task.t()) :: Chaperon.Session.t()
Adds a given Task
to session
under a given name
.
add_error(session, action, error)
View Sourceadd_error( Chaperon.Session.t(), Chaperon.Actionable.t(), {:error, Chaperon.Session.Error.t()} ) :: Chaperon.Session.t()
Stores a Chaperon.Session.Error
in session
for a given action
for later
inspection.
add_metric(session, metric, val)
View Sourceadd_metric(Chaperon.Session.t(), metric(), any()) :: Chaperon.Session.t()
Stores a given metric val
under a given name
in session
.
add_result(session, action, result)
View Sourceadd_result(Chaperon.Session.t(), Chaperon.Actionable.t(), any()) :: Chaperon.Session.t()
Adds a given HTTP request result
to session
for the given action
.
add_ws_result(session, action, result)
View Sourceadd_ws_result(Chaperon.Session.t(), Chaperon.Actionable.t(), any()) :: Chaperon.Session.t()
Adds a given WebSocket action result
to session
for a given action
.
assign(session, assignments)
View Sourceassign(Chaperon.Session.t(), Keyword.t()) :: Chaperon.Session.t()
Assigns a given list of key-value pairs (as a Keyword
list) in session
for further usage later.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{} |> assign(foo: 1, bar: "hello")
iex> session.assigned.foo
1
iex> session.assigned.bar
"hello"
iex> session.assigned
%{foo: 1, bar: "hello"}
assign(session, namespace, assignments)
View Sourceassign(Chaperon.Session.t(), atom(), Keyword.t()) :: Chaperon.Session.t()
Assigns a given list of key-value pairs (as a Keyword
list) under a given
namespace in session
for further usage later.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{} |> assign(:api, auth_token: "auth123", login: "foo@bar.com")
iex> session.assigned.api
%{auth_token: "auth123", login: "foo@bar.com"}
iex> session.assigned.api.auth_token
"auth123"
iex> session.assigned.api.login
"foo@bar.com"
iex> session.assigned
%{api: %{auth_token: "auth123", login: "foo@bar.com"}}
async(session, target, args \\ [], task_name \\ nil)
View Sourceasync(Chaperon.Session.t(), atom() | {atom(), atom()}, [any()], atom() | nil) :: Chaperon.Session.t()
Runs a given function with args asynchronously from session
.
async_task(session, task_name)
View Sourceasync_task(Chaperon.Session.t(), atom()) :: Task.t() | [Task.t()]
Returns a single task or a list of tasks associated with a given task_name
in session
.
await(session, task_name)
View Sourceawait(Chaperon.Session.t(), atom()) :: Chaperon.Session.t()
await(Chaperon.Session.t(), [atom()]) :: Chaperon.Session.t()
Await all async tasks for the given task_names
in session
.
await(session, task_name, task)
View Sourceawait(Chaperon.Session.t(), atom(), Task.t()) :: Chaperon.Session.t()
await(Chaperon.Session.t(), atom(), [Task.t()]) :: Chaperon.Session.t()
await_all(session, task_name)
View Sourceawait_all(Chaperon.Session.t(), atom()) :: Chaperon.Session.t()
Await all async tasks with a given task_name
in session
.
await_signal(session, callback)
View Sourceawait_signal( Chaperon.Session.t(), any() | (Chaperon.Session.t(), any() -> Chaperon.Session.t()) ) :: Chaperon.Session.t()
Await a given signal in the current session and returns session afterwards.
Example:
session
|> await_signal(:continue_search)
|> get("/search", params: [query: "Got load test?"])
await_signal(session, expected_signal, timeout)
View Sourceawait_signal(Chaperon.Session.t(), any(), non_neg_integer()) :: Chaperon.Session.t()
Await an expected signal with a given timeout.
Example:
session
|> await_signal(:continue_search, 5 |> seconds)
|> get("/search", params: [query: "Got load test?"])
await_signal_or_timeout(session, timeout, callback \\ nil)
View Sourceawait_signal_or_timeout( Chaperon.Session.t(), non_neg_integer(), nil | (Chaperon.Session.t(), any() -> Chaperon.Session.t()) ) :: Chaperon.Session.t()
Await any incoming signal for current session within given timeout. If callback is provided, it will be called with the session and the received signal value.
Example:
session
|> await_signal_or_timeout(5 |> seconds, fn(session, signal) ->
session
|> log_info("Got signal")
|> assign(signal: signal)
end)
# or using an atom as the callback:
def run(session) do
session
|> await_signal_or_timeout(5 |> seconds, :got_signal)
end
def got_signal(session, signal) do
session
|> log_info("Got signal")
|> assign(signal: signal)
end
call(session, func, args \\ [])
View Sourcecall(Chaperon.Session.t(), func(), [any()]) :: Chaperon.Session.t()
Calls a function inside the session
's scenario module with the given name
and args, returning the resulting session.
call_callback(session, func_name, arg)
View Sourcecall_callback(Chaperon.Session.t(), result_callback(), any()) :: Chaperon.Session.t()
Calls a callback
with session
and an additional argument.
If the given callback is nil, simply returns session
.
If the callback is a function, call it with session
and the extra argument.
If it's an atom, call the function with that name in session
's currently
running scenario module.
call_traced(session, func, args \\ [])
View Sourcecall_traced(Chaperon.Session.t(), func(), [any()]) :: Chaperon.Session.t()
Calls a given function or a function with the given name and args, then
captures duration metrics in session
.
cc_spread(session, func_name, opts \\ [])
View Sourcecc_spread(Chaperon.Session.t(), atom(), cc_spread_options()) :: Chaperon.Session.t()
Concurrently spreads a given action with a given rate over a given time
interval within session
.
Concurrently spreads a given action with a given rate over a given time
interval within session
.
cc_spread(session, func_name, rate, interval, task_name)
View Sourcecc_spread( Chaperon.Session.t(), atom(), Chaperon.Action.SpreadAsync.rate(), Chaperon.Action.SpreadAsync.time(), atom() | nil ) :: Chaperon.Session.t()
config(session, key)
View Sourceconfig(Chaperon.Session.t(), config_key()) :: any()
Get a (possibly nested) config value.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{config: %{foo: 1, bar: %{val1: "V1", val2: "V2"}}}
iex> session.config
%{foo: 1, bar: %{val1: "V1", val2: "V2"}}
iex> session |> config(:foo)
1
iex> try do
iex> session |> config(:invalid) # does not exist
iex> rescue
iex> _ in Chaperon.Session.RequiredConfigMissingError -> :failed
iex> end
:failed
iex> session |> config([:bar, :val1])
"V1"
iex> session |> config([:bar, :val2])
"V2"
iex> session |> config("bar.val1")
"V1"
iex> session |> config("bar.val2")
"V2"
config(session, key, default_val)
View Sourceconfig(Chaperon.Session.t(), config_key(), any()) :: any()
Get a (possibly nested) config value and return the given default value, if config value does not exist.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{config: %{foo: 1, bar: %{val1: "V1", val2: "V2"}}}
iex> session.config
%{foo: 1, bar: %{val1: "V1", val2: "V2"}}
iex> session |> config(:foo)
1
iex> try do
iex> session |> config(:invalid) # no default value given
iex> rescue
iex> _ in Chaperon.Session.RequiredConfigMissingError -> :failed
iex> end
:failed
iex> session |> config(:invalid, "default")
"default"
iex> session |> config([:bar, :val1])
"V1"
iex> session |> config([:bar, :val2])
"V2"
iex> session |> config("bar.val1")
"V1"
iex> session |> config("bar.val2")
"V2"
delay(session, duration)
View Sourcedelay(Chaperon.Session.t(), Chaperon.Timing.duration()) :: Chaperon.Session.t()
Delays further execution of session
by a given duration
.
duration
can also be {:random, integer_val}
in which case random_delay
is called with integer_val
.
Example:
session
|> delay(3 |> seconds)
|> get("/")
# or with random delay up to 3 seconds:
session
|> delay({:random, 3 |> seconds})
|> get("/")
delete(session, path, opts \\ [])
View Sourcedelete(Chaperon.Session.t(), String.t(), Chaperon.Action.HTTP.options()) :: Chaperon.Session.t()
Performs a HTTP DELETE request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
delete_cookies(session)
View Sourcedelete_cookies(Chaperon.Session.t()) :: Chaperon.Session.t()
Deletes all cookies from session
's cookie store.
iex> session = %Chaperon.Session{cookies: ["cookie_val1", "cookie_val2"]}
iex> session = session |> Chaperon.Session.delete_cookies
iex> session.cookies
[]
error(session, reason)
View Sourceerror(Chaperon.Session.t(), any()) :: {:error, Chaperon.Session.Error.t()}
Returns a Chaperon.Session.Error
for the given session
and with a given
reason
.
Returns a Chaperon.Session.Error
for the given session
and with a given
reason
for a given action
.
get(session, path, opts \\ [])
View Sourceget(Chaperon.Session.t(), String.t(), Chaperon.Action.HTTP.options()) :: Chaperon.Session.t()
Performs a HTTP GET request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
loop(session, action_name, duration)
View Sourceloop(Chaperon.Session.t(), atom(), Chaperon.Timing.duration()) :: Chaperon.Session.t()
Loops a given action for a given duration, returning the resulting session at the end.
merge(session, other_session)
View Sourcemerge(Chaperon.Session.t(), Chaperon.Session.t()) :: Chaperon.Session.t()
Merges two session's results & metrics and returns the resulting session.
Merges errors of two sessions.
merge_metrics(session, metrics)
View Sourcemerge_metrics(Chaperon.Session.t(), map()) :: Chaperon.Session.t()
Merges metrics of two sessions.
merge_results(session, results)
View Sourcemerge_results(Chaperon.Session.t(), map()) :: Chaperon.Session.t()
Merges results of two sessions.
Returns the session
s configured name or scenario's module name.
ok(session)
View Sourceok(Chaperon.Session.t()) :: {:ok, Chaperon.Session.t()}
Returns {:ok, reason}
.
patch(session, path, opts)
View Sourcepatch(Chaperon.Session.t(), String.t(), Chaperon.Action.HTTP.options()) :: Chaperon.Session.t()
Performs a HTTP PATCH request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
post(session, path, opts \\ [])
View Sourcepost(Chaperon.Session.t(), String.t(), Chaperon.Action.HTTP.options()) :: Chaperon.Session.t()
Performs a HTTP POST request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
put(session, path, opts \\ [])
View Sourceput(Chaperon.Session.t(), String.t(), Chaperon.Action.HTTP.options()) :: Chaperon.Session.t()
Performs a HTTP PUT request on session
's base_url and path
.
Takes an optional list of options to be passed to HTTPotion
.
random_delay(session, max_duration)
View Sourcerandom_delay(Chaperon.Session.t(), Chaperon.Timing.duration()) :: Chaperon.Session.t()
Delays further execution of session
by a random value up to the given
duration
.
remove_async_task(session, task_name, task)
View Sourceremove_async_task(Chaperon.Session.t(), atom(), Task.t()) :: Chaperon.Session.t()
Removes a Task
with a given task_name
from session
.
repeat(session, func, amount)
View Sourcerepeat(Chaperon.Session.t(), func(), non_neg_integer()) :: Chaperon.Session.t()
Repeats calling a given function with session a given amount of times, returning the resulting session at the end.
Example
session
|> repeat(:foo, 2)
# same as:
session
|> foo
|> foo
repeat(session, func, args, amount)
View Sourcerepeat(Chaperon.Session.t(), func(), [any()], non_neg_integer()) :: Chaperon.Session.t()
Repeats calling a given function with session and additional args a given amount of times, returning the resulting session at the end.
Example
session
|> repeat(:foo, ["bar", "baz"], 2)
# same as:
session
|> foo("bar", "baz") |> foo("bar", "baz")
repeat_traced(session, func, amount)
View Sourcerepeat_traced(Chaperon.Session.t(), func(), non_neg_integer()) :: Chaperon.Session.t()
Repeats calling a given function with session a given amount of times, returning the resulting session at the end. Also traces durations for all calls to the given function.
Example
session
|> repeat_traced(:foo, 2)
# same as:
session
|> call_traced(:foo)
|> call_traced(:foo)
repeat_traced(session, func, args, amount)
View Sourcerepeat_traced(Chaperon.Session.t(), func(), [any()], non_neg_integer()) :: Chaperon.Session.t()
Repeats calling a given function with session and additional args a given amount of times, returning the resulting session at the end.
Example
session
|> repeat_traced(:foo, ["bar", "baz"], 2)
# same as:
session
|> call_traced(:foo, ["bar", "baz"])
|> call_traced(:foo, ["bar", "baz"])
retry_on_error(session, func, args \\ [], opts \\ [retries: 1, random_delay: 1000])
View Sourceretry_on_error(Chaperon.Session.t(), func(), [any()], retry_options()) :: Chaperon.Session.t()
Call a given function (with arguments). If any exception is raised, retry the call a given amount of times (defaults to 1 retry). The retry can be delayed by a fixed or random duration (defaults to 1s).
Example:
session
|> retry_on_error(:publish, ["post title"], retries: 10, delay: 0.5 |> seconds)
# call function without args
|> retry_on_error(:cleanup, [], retries: 10, delay: 0.5 |> seconds)
# retry once by default
session
|> retry_on_error(:publish, ["post title"], random_delay: 5 |> seconds)
# retry once with default delay of 1s
session
|> retry_on_error(:publish, ["post title"])
# retry function without args and default options
session
|> retry_on_error(:publish_default)
run_action(session, action)
View Sourcerun_action(Chaperon.Session.t(), Chaperon.Actionable.t()) :: Chaperon.Session.t()
Runs a given action within session
and returns the resulting
session.
Runs a potentially configured callback for a given action in case of success.
In case of failure, runs the configured error callback with an
{:error, reason}
tuple.
For more info have a look at Chaperon.Action.callback/1
and
Chaperon.Action.error_callback/1
.
run_scenario(session, scenario)
View Sourcerun_scenario(Chaperon.Session.t(), Chaperon.Action.RunScenario.scenario()) :: Chaperon.Session.t()
Runs & captures metrics of running another Chaperon.Scenario
from session
using session
s config.
run_scenario(session, scenario, config, merge_config \\ true)
View Sourcerun_scenario( Chaperon.Session.t(), Chaperon.Action.RunScenario.scenario(), map(), boolean() ) :: Chaperon.Session.t()
Runs & captures metrics of running another Chaperon.Scenario
from session
with a given config
.
Runs & captures metrics of running another Chaperon.Scenario
from session
with a given config
on a random node in the Chaperon cluster.
schedule_scenario(session, scenario, config, merge_config \\ true)
View Sourceschedule_scenario( Chaperon.Session.t(), Chaperon.Action.RunScenario.scenario(), map(), boolean() ) :: Chaperon.Session.t()
Runs & captures metrics of running another Chaperon.Scenario
from session
with a given config
.
Returns session
's errors wrapped with session
's name.
Returns session
's metrics wrapped with session
's name.
Returns session
's results wrapped with session
's name.
set_config(session, assignments)
View Sourceset_config(Chaperon.Session.t(), Keyword.t(any())) :: Chaperon.Session.t()
Updates a session's config based on a given Keyword list of new values to be
used for config
in session
.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{config: %{foo: 1, bar: "hello"}}
iex> session.config
%{foo: 1, bar: "hello"}
iex> session = session |> set_config(foo: 10, baz: "wat")
iex> session.config.foo
10
iex> session.config.bar
"hello"
iex> session.config.baz
"wat"
iex> session.config
%{foo: 10, bar: "hello", baz: "wat"}
set_config(session, namespace, assignments)
View Sourceset_config(Chaperon.Session.t(), atom(), Keyword.t(any())) :: Chaperon.Session.t()
Updates a session's config based on a given Keyword list of new values inside
a given namespace to be used for config
in session
.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{config: %{foo: 1, bar: %{baz: "hello", quux: 0}}}
iex> session.config
%{foo: 1, bar: %{baz: "hello", quux: 0}}
iex> session = session |> set_config(:bar, quux: 10)
iex> session.config.bar.quux
10
iex> session.config.bar
%{baz: "hello", quux: 10}
iex> session.config
%{foo: 1, bar: %{baz: "hello", quux: 10}}
signal(session, name, signal)
View Sourcesignal(Chaperon.Session.t(), atom(), any()) :: Chaperon.Session.t()
Send a signal to the current session's async task with the given name.
Example:
# scenario run function
def run(session) do
session
|> async(:search_entries, ["chaperon", "load testing"])
|> async(:do_other_stuff)
|> signal(:search_entries, :continue_search)
end
def search_entries(session, tag1, tag2) do
session
|> get("/search", json: [tag: tag1])
|> await_signal(:continue_search)
|> get("/search", json: [tag: tag2])
end
signal_parent(session, signal)
View Sourcesignal_parent(Chaperon.Session.t(), any()) :: Chaperon.Session.t()
Sends a signal to the current session's parent session (that spawned it via
a call to Session.async
).
Example:
# scenario run function
def run(session) do
stream_path = "/secret/live/stream.json"
session
|> async(:connect_to_stream, [stream_path])
|> await_signal({:connected_to_stream, stream_path})
# ...
end
def connect_to_stream(session, stream_path) do
session
|> ws_connect(stream_path)
|> signal_parent({:connected_to_stream, stream_path})
|> stream_data
end
# ...
skip_query_params_in_metrics(session)
View Sourceskip_query_params_in_metrics(Chaperon.Session.t()) :: Chaperon.Session.t()
store_response_cookies(session, response)
View Sourcestore_response_cookies(Chaperon.Session.t(), HTTPoison.Response.t()) :: Chaperon.Session.t()
Stores HTTP response cookies in session
cookie store for further outgoing
requests.
time(session, metric, func)
View Sourcetime( Chaperon.Session.t(), metric(), (Chaperon.Session.t() -> Chaperon.Session.t()) ) :: Chaperon.Session.t()
Records a custom metric for the duration of calling a given function with the
current Chaperon.Session
.
Example:
# records a metric named :my_metric with the duration of calling
# the given function
session
|> time(:my_action, fn session ->
# do stuff with session
# and at the end return session from inside this function
end)
time(session, metric, module, func, args \\ [])
View Sourcetime(Chaperon.Session.t(), metric(), atom(), atom(), [any()]) :: Chaperon.Session.t()
Records a custom metric for the duration of calling a given function with the
current Chaperon.Session
.
Example:
# records a metric named :my_metric with the duration of calling
# the given function in the module with the given args.
session
|> time(:my_action, MyModule, :my_func, [arg1, arg2])
# this would record the duration of calling:
# MyModule.my_func(session, arg1, arg2)
timeout(session)
View Sourcetimeout(Chaperon.Session.t()) :: non_neg_integer()
Returns the session's configured timeout or the default timeout, if none specified.
Example
iex> session = %Chaperon.Session{config: %{timeout: 10}}
iex> session |> Chaperon.Session.timeout
10
update_assign(session, assignments)
View Sourceupdate_assign(Chaperon.Session.t(), Keyword.t((any() -> any()))) :: Chaperon.Session.t()
Updates assignments based on a given Keyword list of functions to be used for
updating assigned
in session
.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{} |> assign(foo: 1, bar: "hello")
iex> session.assigned
%{foo: 1, bar: "hello"}
iex> session = session |> update_assign(foo: &(&1 + 2))
iex> session.assigned.foo
3
iex> session.assigned.bar
"hello"
iex> session.assigned
%{foo: 3, bar: "hello"}
update_assign(session, namespace, assignments)
View Sourceupdate_assign(Chaperon.Session.t(), atom(), Keyword.t((any() -> any()))) :: Chaperon.Session.t()
Updates assignments based on a given Keyword list of functions to be used for
updating assigned
within namespace
in session
.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{} |> assign(:api, auth_token: "auth123", login: "foo@bar.com")
iex> session.assigned.api
%{auth_token: "auth123", login: "foo@bar.com"}
iex> session = session |> update_assign(:api, login: &("test" <> &1))
iex> session.assigned.api.login
"testfoo@bar.com"
iex> session.assigned.api
%{auth_token: "auth123", login: "testfoo@bar.com"}
update_config(session, assignments)
View Sourceupdate_config(Chaperon.Session.t(), Keyword.t((any() -> any()))) :: Chaperon.Session.t()
Updates a session's config based on a given Keyword list of functions to be
used for updating config
in session
.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{config: %{foo: 1, bar: "hello"}}
iex> session.config
%{foo: 1, bar: "hello"}
iex> session = session |> update_config(foo: &(&1 + 2))
iex> session.config.foo
3
iex> session.config.bar
"hello"
iex> session.config
%{foo: 3, bar: "hello"}
update_config(session, namespace, assignments)
View Sourceupdate_config(Chaperon.Session.t(), atom(), Keyword.t((any() -> any()))) :: Chaperon.Session.t()
Updates a session's config based on a given Keyword list of functions to be
used for updating config
in session
under a given namespace.
Example
iex> alias Chaperon.Session; import Session
iex> session = %Session{config: %{foo: 1, bar: %{baz: "hello", quux: 0}}}
iex> session.config
%{foo: 1, bar: %{baz: "hello", quux: 0}}
iex> session = session |> update_config(:bar, quux: &(&1 + 2))
iex> session.config
%{foo: 1, bar: %{baz: "hello", quux: 2}}
ws_await_recv(session, expected_message, options \\ [])
View Sourcews_await_recv(Chaperon.Session.t(), any(), Keyword.t()) :: Chaperon.Session.t()
Performs a WebSocket message receive on session
s WebSocket connection.
Takes an optional list of options
to be passed along to Socket.Web.recv/2
.
ws_close(session, options \\ [])
View Sourcews_close(Chaperon.Session.t(), Keyword.t()) :: Chaperon.Session.t()
Closes the session's websocket connection.
Takes an optional list of options
to be passed along to Socket.Web.close/2
.
ws_connect(session, path, options \\ [])
View Sourcews_connect(Chaperon.Session.t(), String.t(), Keyword.t()) :: Chaperon.Session.t()
Performs a WebSocket connection attempt on session
's base_url and
path
.
ws_recv(session, options \\ [])
View Sourcews_recv(Chaperon.Session.t(), Keyword.t()) :: Chaperon.Session.t()
Performs a WebSocket message receive on session
s WebSocket connection.
Takes an optional list of options
to be passed along to Socket.Web.recv/2
.
ws_send(session, msg, options \\ [])
View Sourcews_send(Chaperon.Session.t(), any(), Keyword.t()) :: Chaperon.Session.t()
Performs a WebSocket message send on session
s WebSocket connection.
Takes an optional list of options
to be passed along to Socket.Web.send/3
.
Makes a given function call async for session
.
Example
session
~> foo
~> bar(1,2,3)
Is the same as:
session
|> async(:foo)
|> async(:bar, [1,2,3])