test(ci): add proptests chekcing to the makefile

This commit is contained in:
JianBo He 2021-02-01 14:47:18 +08:00
parent 49a59ea564
commit 8954fffe2a
3 changed files with 22 additions and 52 deletions

View File

@ -31,6 +31,10 @@ get-dashboard:
eunit: $(REBAR) eunit: $(REBAR)
$(REBAR) eunit $(REBAR) eunit
.PHONY: proper
proper: $(REBAR)
$(REBAR) as test proper -d test/props -c
.PHONY: ct .PHONY: ct
ct: $(REBAR) ct: $(REBAR)
$(REBAR) ct --name 'test@127.0.0.1' -c -v $(REBAR) ct --name 'test@127.0.0.1' -c -v
@ -40,7 +44,7 @@ cover: $(REBAR)
$(REBAR) cover $(REBAR) cover
.PHONY: coveralls .PHONY: coveralls
cover: $(REBAR) coveralls: $(REBAR)
$(REBAR) as test coveralls send $(REBAR) as test coveralls send
.PHONY: $(REL_PROFILES) .PHONY: $(REL_PROFILES)

View File

@ -290,58 +290,22 @@ prop_message_acked() ->
true true
end). end).
prop_try_again() ->
Setup = fun() ->
logger:set_module_level(emqx_web_hook, emergency),
meck:new(httpc, [passthrough, no_history]),
meck:expect(httpc, request,
fun(Method, {Url, [], ContentType, Body}, _HttpOpts, _Opt) ->
self() ! {Method, Url, ContentType, Body}, {error, get(code)}
end),
meck:new(emqx_metrics, [passthrough, no_history]),
meck:expect(emqx_metrics, inc, fun(_) -> ok end)
end,
Teardown = fun() ->
meck:unload(httpc),
meck:unload(emqx_metrics),
logger:set_module_level(emqx_web_hook, debug)
end,
?SETUP(fun() -> Setup(), Teardown end,
?FORALL({ConnInfo, ConnProps, Env, Code},
{conninfo(), conn_properties(), empty_env(), http_code()},
begin
%% pre-set error code
put(code, Code),
%% run hook
ok = emqx_web_hook:on_client_connect(ConnInfo, ConnProps, Env),
Bodys = receive_http_request_bodys(),
Body = emqx_json:encode(
#{action => client_connect,
node => stringfy(node()),
clientid => maps:get(clientid, ConnInfo),
username => maybe(maps:get(username, ConnInfo)),
ipaddress => peer2addr(maps:get(peername, ConnInfo)),
keepalive => maps:get(keepalive, ConnInfo),
proto_ver => maps:get(proto_ver, ConnInfo)
}),
[ B = Body || B <- Bodys],
if Code == socket_closed_remotely ->
4 = length(Bodys);
true -> ok
end,
true
end)).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Helper %% Helper
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
do_setup() -> do_setup() ->
%% Pre-defined envs
application:set_env(emqx_web_hook, path, "path"),
application:set_env(emqx_web_hook, headers, []),
meck:new(ehttpc_pool, [passthrough, no_history]),
meck:expect(ehttpc_pool, pick_worker, fun(_, _) -> ok end),
Self = self(), Self = self(),
meck:new(httpc, [passthrough, no_history]), meck:new(ehttpc, [passthrough, no_history]),
meck:expect(httpc, request, meck:expect(ehttpc, request,
fun(Method, {Url, [], ContentType, Body}, _HttpOpts, _Opt) -> fun(_ClientId, Method, {Path, Headers, Body}) ->
Self ! {Method, Url, ContentType, Body}, {ok, ok} Self ! {Method, Path, Headers, Body}, {ok, ok, ok}
end), end),
meck:new(emqx_metrics, [passthrough, no_history]), meck:new(emqx_metrics, [passthrough, no_history]),
@ -349,7 +313,8 @@ do_setup() ->
ok. ok.
do_teardown(_) -> do_teardown(_) ->
meck:unload(httpc), meck:unload(ehttpc_pool),
meck:unload(ehttpc),
meck:unload(emqx_metrics). meck:unload(emqx_metrics).
maybe(undefined) -> null; maybe(undefined) -> null;
@ -372,7 +337,7 @@ stringfy(Term) ->
receive_http_request_body() -> receive_http_request_body() ->
receive receive
{post, "http://127.0.0.1", "application/json", Body} -> {post, _, _, Body} ->
Body Body
after 100 -> after 100 ->
exit(waiting_message_timeout) exit(waiting_message_timeout)
@ -383,7 +348,7 @@ receive_http_request_bodys() ->
receive_http_request_bodys_(Acc) -> receive_http_request_bodys_(Acc) ->
receive receive
{post, "http://127.0.0.1", "application/json", Body} -> {post, _, _, Body} ->
receive_http_request_bodys_([Body|Acc]) receive_http_request_bodys_([Body|Acc])
after 1000 -> after 1000 ->
lists:reverse(Acc) lists:reverse(Acc)

View File

@ -28,7 +28,8 @@ plugins() ->
]. ].
test_plugins() -> test_plugins() ->
[ {coveralls, {git, "https://github.com/emqx/coveralls-erl", {branch, "github"}}} [ rebar3_proper,
{coveralls, {git, "https://github.com/emqx/coveralls-erl", {branch, "github"}}}
]. ].
test_deps() -> test_deps() ->