summaryrefslogtreecommitdiff
path: root/p11p-daemon/src
diff options
context:
space:
mode:
authorLinus Nordberg <linus@sunet.se>2020-02-12 17:12:43 +0100
committerLinus Nordberg <linus@sunet.se>2020-02-14 12:17:16 +0100
commit920995ca6e2ef7c4993b0196c2556409eade04d1 (patch)
tree0e12ec19f4268b7495e5ca5c798d3844dda91a24 /p11p-daemon/src
parent37277c3ba0119f50af8ffff014ce13b93f225557 (diff)
Make probability of dropping a request, for testing, configurable
Diffstat (limited to 'p11p-daemon/src')
-rw-r--r--p11p-daemon/src/p11p_client.erl7
-rw-r--r--p11p-daemon/src/p11p_config.erl27
2 files changed, 27 insertions, 7 deletions
diff --git a/p11p-daemon/src/p11p_client.erl b/p11p-daemon/src/p11p_client.erl
index d6c73ac..fd101c5 100644
--- a/p11p-daemon/src/p11p_client.erl
+++ b/p11p-daemon/src/p11p_client.erl
@@ -186,10 +186,11 @@ code_change(_OldVersion, State, _Extra) ->
{ok, State}.
%% Private
-do_send(Port, Buf) ->
- Rand = rand:uniform(100), %% + 10,
+send_request(Port, Buf) ->
+ Rand = rand:uniform(100),
+ Prob = p11p_config:testing_drop_prob(),
if
- Rand =< 10 ->
+ Rand =< Prob ->
lager:debug("~p: faking unresponsive token (~p) by not sending",
[self(), Port]);
true ->
diff --git a/p11p-daemon/src/p11p_config.erl b/p11p-daemon/src/p11p_config.erl
index d24aad6..c4bfbcd 100644
--- a/p11p-daemon/src/p11p_config.erl
+++ b/p11p-daemon/src/p11p_config.erl
@@ -8,10 +8,16 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-export([start_link/0]).
--export([nameof/1]).
--export([tokens/0]).
--export([proxyapp_bin_path/0, modules_for_token/1, module_path/1, module_env/1,
- token_balance/1, token_retries/1, token_timeout/1]).
+-export([modules_for_token/1,
+ module_path/1,
+ module_env/1,
+ nameof/1,
+ proxyapp_bin_path/0,
+ testing_drop_prob/0,
+ tokens/0,
+ token_balance/1,
+ token_retries/1,
+ token_timeout/1]).
%%% Records and types %%%
-record(p11module, {
@@ -32,6 +38,7 @@
-record(state, {
proxyapp_bin_path :: string(),
+ testing_drop_prob :: non_neg_integer(),
tokens :: #{string() => token()}
}).
@@ -46,6 +53,8 @@ init(_Args) ->
handle_call(proxyapp_bin_path, _From, S = #state{proxyapp_bin_path = Path}) ->
{reply, Path, S};
+handle_call(testing_drop_prob, _From, S = #state{testing_drop_prob = P}) ->
+ {reply, P, S};
handle_call(tokens, _From, State = #state{tokens = Tokens}) ->
{reply, maps:values(Tokens), State};
handle_call({modules_for_token, TokName}, _, S = #state{tokens = Tokens}) ->
@@ -86,6 +95,9 @@ start_link() ->
proxyapp_bin_path() ->
gen_server:call(?MODULE, proxyapp_bin_path).
+testing_drop_prob() ->
+ gen_server:call(?MODULE, testing_drop_prob).
+
-spec tokens() -> [token()].
tokens() ->
gen_server:call(?MODULE, tokens).
@@ -129,6 +141,9 @@ init_state() ->
proxyapp_bin_path = application:get_env(p11p,
proxyapp_bin_path,
?PROXYAPP_DEFAULT),
+ testing_drop_prob = application:get_env(p11p,
+ testing_drop_prob,
+ 0),
tokens = conf_tokens(application:get_env(p11p,
vtokens,
[]))}.
@@ -139,6 +154,10 @@ init_state(Filename) ->
string,
"proxyapp_bin_path",
?PROXYAPP_DEFAULT),
+ testing_drop_prob = p11p_config_file:get(Config,
+ integer,
+ "testing_drop_prob",
+ 0),
tokens = conf_tokens(p11p_config_file:get(Config,
section,
"vtokens",