diff options
author | Linus Nordberg <linus@sunet.se> | 2020-02-12 17:12:43 +0100 |
---|---|---|
committer | Linus Nordberg <linus@sunet.se> | 2020-02-14 12:17:16 +0100 |
commit | 920995ca6e2ef7c4993b0196c2556409eade04d1 (patch) | |
tree | 0e12ec19f4268b7495e5ca5c798d3844dda91a24 /p11p-daemon | |
parent | 37277c3ba0119f50af8ffff014ce13b93f225557 (diff) |
Make probability of dropping a request, for testing, configurable
Diffstat (limited to 'p11p-daemon')
-rw-r--r-- | p11p-daemon/config/sys.config | 26 | ||||
-rw-r--r-- | p11p-daemon/src/p11p_client.erl | 7 | ||||
-rw-r--r-- | p11p-daemon/src/p11p_config.erl | 27 |
3 files changed, 45 insertions, 15 deletions
diff --git a/p11p-daemon/config/sys.config b/p11p-daemon/config/sys.config index 74d2c21..e697383 100644 --- a/p11p-daemon/config/sys.config +++ b/p11p-daemon/config/sys.config @@ -4,20 +4,30 @@ [ {loglevel, 3}, {proxyapp_bin_path, "/usr/lib/x86_64-linux-gnu/p11-kit/p11-kit-remote"}, - {groups, + {testing_drop_prob, 0}, + {vtokens, [{"vtoken0", [ - {mode, {balance, [2]}}, + {timeout, 2000}, {modules, - [{"softhsm2", "/usr/lib/softhsm/libsofthsm2.so"}, - {"bogusmod_0", "/usr/lib/softhsm/libsofthsm2.so"}]} + [ + {"softhsm2", "/usr/lib/softhsm/libsofthsm2.so"}, + {"bogusmod_0", "/usr/lib/softhsm/libsofthsm2.so"} + ]} ]}, {"vtoken1", - [{modules, - [{"softhsm2", "/usr/lib/softhsm/libsofthsm2.so", [{"SOME_ENV", "hi env!"}]}]} + [ + %% Try failover twice, even if we have only one token. In + %% effect, retry the same token once after a failure. + {failover, 2}, + {timeout, 1000}, + {modules, + [ + {"softhsm2", "/usr/lib/softhsm/libsofthsm2.so", [{"SOFTHSM2_CONF", "/home/linus/usr/src/p11p/tests/softhsm/softhsm2.conf"}]} + ]} ]} - ]} - ]}, + ]} + ]}, {lager, [{handlers, [ 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", |