-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdummy_scenario.erl
More file actions
86 lines (74 loc) · 3.79 KB
/
Copy pathdummy_scenario.erl
File metadata and controls
86 lines (74 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-module(dummy_scenario).
-behaviour(amoc_scenario).
%% var1 must be equal to one of the values in the verification list
%% and the default value is def1
-required_variable(#{name => var1, description => "description1",
default_value => def1,
verification => [def1, another_value]}).
-required_variable([
%% var2 must be positively verified by the test_verification_function/1 function.
%% verification function must be supplied as an mfa of the format
%% '{module, function, arity}', or a fun of the format `fun module:function/arity`.
%% Note that it must be an exported function, otherwise it will not pass compilation.
#{name => var2, description => "description2", default_value => def2,
verification => {?MODULE, test_verification_function, 1}},
#{name => var3, description => "description3", default_value => def3,
verification => {?MODULE, test_verification_function, 1}}]).
%% 'none' is a predefined verification function which accepts all the values
-required_variable(#{name => var4, description => "description4",
default_value => def4,
verification => none}).
-required_variable([
%% when verification method is not set, it defaults to `none`
#{name => var5, description => "description5", default_value => def5},
%% when value is not set, it defaults to `undefined`
#{name => var6, description => "description6"},
#{name => nodes, description => "this variable is set for docker "
"container via AMOC_NODES env"},
#{name => test1, description => "this variable is to be set via initial settings"},
#{name => test2, update => none, description => "this one to be updated"}]).
-required_variable([
#{name => global_test1, scope => global,
description => "this variable is to be set via initial settings"},
#{name => global_test2, scope => global, update => none,
description => "this one to be updated"}]).
%% parameter verification method
-export([test_verification_function/1]).
%% amoc_scenario behaviour
-export([init/0, start/1]).
test_verification_function(def2) -> true;
test_verification_function(_) -> {true, new_value}.
-spec init() -> ok.
init() ->
%% amoc follows a couple of rules during the scenario initialisation:
%% - if any parameter verification fails, amoc will not start
%% the scenario and the init/0 function is not triggered.
%% - if the init/0 function fails, amoc will not start any users (by
%% calling a start/1 or start2 function)
%% if the REST API reports that scenario is executed, than all the
%% initialisation steps described above have passed successfully
def1 = amoc_config:get(var1, def_value),
def2 = amoc_config:get(var2, def_value),
new_value = amoc_config:get(var3, def_value),
def4 = amoc_config:get(var4, def_value),
def5 = amoc_config:get(var5, def_value),
def_value = amoc_config:get(var6, def_value),
undefined = amoc_config:get(var6),
[_ | _] = amoc_config:get(nodes),
%% it doesn't matter if an undeclared_variable is passed through the
%% os or erlang app environment variable. if it's not declared using
%% the -required_variable(...) attribute, then any attempt to get it
%% results in exception.
{invalid_setting, undeclared_variable} =
(catch amoc_config:get(undeclared_variable)),
%% this variable is set via settings
<<"test_value2">> = amoc_config:get(test1),
%% dummy_var variable is defined in the dummy_helper module.
%% if dummy_helper is not propagated, then this call crashes
default_value = amoc_config:get(dummy_var),
ok.
-spec start(amoc_scenario:user_id()) -> any().
start(_Id) ->
%%sleep 15 minutes
timer:sleep(timer:minutes(15)),
amoc_user:stop().