View Source Developing a scenario
Developing a scenario
A scenario specification is an Erlang or Elixir module that implements the amoc_scenario
behaviour.
It has to export two callback functions:
init/0
- called only once per test run on every node, at the very beginning. It can be used for setting up initial (global) state: metrics, database connections, etc. It can return anok
or a tuple{ok, State}
from which theState
may be passed to every user.start/1
orstart/2
- implements the actual scenario and is executed for each user, in the context of that user's process. The first argument is the given user's unique integer id. The second, which is optional, is the state, as returned from theinit/0
function.
In addition to that, the scenario module can implement a terminate/0,1
callback;
it has one optional argument – the scenario state, as returned from the init/0
function.
A typical scenario file will look like this:
-module(my_scenario).
-behaviour(amoc_scenario).
-export([init/0]).
-export([start/1]).
init() ->
%% initialize some metrics
ok.
start(Id) ->
%% connect user
%% fetch user's history
%% send some messages
%% wait a little bit
%% send some messages again
ok.
defmodule LoadTest do
@behaviour :amoc_scenario
def init do
## initialize some metrics
:ok
end
def start(id) do
## connect user
## fetch user's history
## send some messages
## wait a little bit
## send some messages again
:ok
end
end
or, using the start/2
function:
-module(my_scenario).
-behaviour(amoc_scenario).
-export([init/0]).
-export([start/2]).
init() ->
%% initialize some metrics
Settings = get_settings(),
{ok, Settings}.
start(Id, Settings) ->
%% connect user using Settings
%% fetch user's history
%% send some messages
%% wait a little bit
%% send some messages again
ok.
defmodule LoadTest do
@behaviour :amoc_scenario
def init do
## initialize some metrics
settings = get_settings()
{:ok, settings}
end
def start(id, settings) do
## connect user using Settings
## fetch user's history
## send some messages
## wait a little bit
## send some messages again
:ok
end
end
For developing XMPP scenarios, we recommend the
esl/escalus library.
If additional dependencies are required by your scenario,
a rebar.config
file can be created inside the scenario
dir
and deps
from that file will be merged with Amoc's dependencies.
Coordinate users
See Amoc coordinator.
Throttle actions
See Amoc throttle.