Compare commits

...

2 Commits

Author SHA1 Message Date
JianBo He 8954fffe2a test(ci): add proptests chekcing to the makefile 2021-02-02 14:55:19 +08:00
JianBo He 49a59ea564 chore(cover): add coverall back 2021-02-02 14:52:09 +08:00
6 changed files with 68 additions and 57 deletions

View File

@ -12,6 +12,14 @@ services:
- ldap_server - ldap_server
networks: networks:
- emqx_bridge - emqx_bridge
environment:
GITHUB_ACTIONS: ${GITHUB_ACTIONS}
GITHUB_TOKEN: ${GITHUB_TOKEN}
GITHUB_RUN_ID: ${GITHUB_RUN_ID}
GITHUB_SHA: ${GITHUB_SHA}
GITHUB_RUN_NUMBER: ${GITHUB_RUN_NUMBER}
GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}
GITHUB_REF: ${GITHUB_REF}
volumes: volumes:
- ../../.:/emqx - ../../.:/emqx
working_dir: /emqx working_dir: /emqx

View File

@ -25,6 +25,7 @@ jobs:
MONGO_TAG: 4 MONGO_TAG: 4
PGSQL_TAG: 13 PGSQL_TAG: 13
LDAP_TAG: 2.4.50 LDAP_TAG: 2.4.50
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
docker-compose -f .ci/apps_tests/docker-compose.yaml build --no-cache docker-compose -f .ci/apps_tests/docker-compose.yaml build --no-cache
docker-compose -f .ci/apps_tests/docker-compose.yaml up -d docker-compose -f .ci/apps_tests/docker-compose.yaml up -d
@ -48,6 +49,7 @@ jobs:
docker exec -i erlang bash -c "make xref" docker exec -i erlang bash -c "make xref"
docker exec -i erlang bash -c "make ct" docker exec -i erlang bash -c "make ct"
docker exec -i erlang bash -c "make cover" docker exec -i erlang bash -c "make cover"
docker exec -i erlang bash -c "make coveralls"
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
if: failure() if: failure()
with: with:

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
@ -39,6 +43,10 @@ ct: $(REBAR)
cover: $(REBAR) cover: $(REBAR)
$(REBAR) cover $(REBAR) cover
.PHONY: coveralls
coveralls: $(REBAR)
$(REBAR) as test coveralls send
.PHONY: $(REL_PROFILES) .PHONY: $(REL_PROFILES)
$(REL_PROFILES:%=%): $(REBAR) get-dashboard $(REL_PROFILES:%=%): $(REBAR) get-dashboard
ifneq ($(shell echo $(@) |grep edge),) ifneq ($(shell echo $(@) |grep edge),)

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

@ -11,8 +11,7 @@
{erl_opts, [warn_unused_vars,warn_shadow_vars,warn_unused_import, {erl_opts, [warn_unused_vars,warn_shadow_vars,warn_unused_import,
warn_obsolete_guard,compressed]}. warn_obsolete_guard,compressed]}.
{overrides,[{add,[{erl_opts,[compressed,deterministic]}]} {overrides,[{add,[{extra_src_dirs, [{"etc", [{recursive,true}]}]}]}
,{add,[{extra_src_dirs, [{"etc", [{recursive,true}]}]}]}
]}. ]}.
{extra_src_dirs, [{"etc", [{recursive,true}]}]}. {extra_src_dirs, [{"etc", [{recursive,true}]}]}.

View File

@ -4,7 +4,7 @@
do(Dir, CONFIG) -> do(Dir, CONFIG) ->
ok = compile_and_load_pase_transforms(Dir), ok = compile_and_load_pase_transforms(Dir),
dump(deps(CONFIG) ++ dialyzer(CONFIG) ++ config()). dump(deps(CONFIG) ++ dialyzer(CONFIG) ++ coveralls() ++ config()).
bcrypt() -> bcrypt() ->
{bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {branch, "0.6.0"}}}. {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {branch, "0.6.0"}}}.
@ -27,28 +27,37 @@ plugins() ->
{er_coap_client, {git, "https://github.com/emqx/er_coap_client", {tag, "v1.0"}}} {er_coap_client, {git, "https://github.com/emqx/er_coap_client", {tag, "v1.0"}}}
]. ].
test_plugins() ->
[ rebar3_proper,
{coveralls, {git, "https://github.com/emqx/coveralls-erl", {branch, "github"}}}
].
test_deps() -> test_deps() ->
[ {bbmustache, "1.10.0"} [ {bbmustache, "1.10.0"}
, {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "1.3.4"}}} , {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "1.3.4"}}}
, meck , meck
]. ].
default_compile_opts() ->
[compressed, deterministic, no_debug_info, warnings_as_errors, {parse_transform, mod_vsn}].
profiles() -> profiles() ->
[ {'emqx', [ {erl_opts, [no_debug_info, warnings_as_errors, {parse_transform, mod_vsn}]} [ {'emqx', [ {erl_opts, default_compile_opts()}
, {relx, relx('emqx')} , {relx, relx('emqx')}
]} ]}
, {'emqx-pkg', [ {erl_opts, [no_debug_info, warnings_as_errors, {parse_transform, mod_vsn}]} , {'emqx-pkg', [ {erl_opts, default_compile_opts()}
, {relx, relx('emqx-pkg')} , {relx, relx('emqx-pkg')}
]} ]}
, {'emqx-edge', [ {erl_opts, [no_debug_info, warnings_as_errors, {parse_transform, mod_vsn}]} , {'emqx-edge', [ {erl_opts, default_compile_opts()}
, {relx, relx('emqx-edge')} , {relx, relx('emqx-edge')}
]} ]}
, {'emqx-edge-pkg', [ {erl_opts, [no_debug_info, warnings_as_errors, {parse_transform, mod_vsn}]} , {'emqx-edge-pkg', [ {erl_opts, default_compile_opts()}
, {relx, relx('emqx-edge-pkg')} , {relx, relx('emqx-edge-pkg')}
]} ]}
, {check, [ {erl_opts, [debug_info, warnings_as_errors, {parse_transform, mod_vsn}]} , {check, [ {erl_opts, [debug_info, warnings_as_errors, {parse_transform, mod_vsn}]}
]} ]}
, {test, [ {deps, test_deps()} , {test, [ {deps, test_deps()}
, {plugins, test_plugins()}
, {erl_opts, [debug_info, {parse_transform, mod_vsn}] ++ erl_opts_i()} , {erl_opts, [debug_info, {parse_transform, mod_vsn}] ++ erl_opts_i()}
]} ]}
]. ].
@ -295,6 +304,26 @@ dialyzer(Config) ->
Config Config
end. end.
coveralls() ->
case {os:getenv("GITHUB_ACTIONS"), os:getenv("GITHUB_TOKEN")} of
{"true", Token} when is_list(Token) ->
Cfgs = [{coveralls_repo_token, Token},
{coveralls_service_job_id, os:getenv("GITHUB_RUN_ID")},
{coveralls_commit_sha, os:getenv("GITHUB_SHA")},
{coveralls_service_number, os:getenv("GITHUB_RUN_NUMBER")},
{coveralls_coverdata, "_build/test/cover/*.coverdata"},
{coveralls_service_name, "github"}],
case os:getenv("GITHUB_EVENT_NAME") =:= "pull_request"
andalso string:tokens(os:getenv("GITHUB_REF"), "/") of
[_, "pull", PRNO, _] ->
[{coveralls_service_pull_request, PRNO} | Cfgs];
_ ->
Cfgs
end;
_ ->
[]
end.
list_dir(Dir) -> list_dir(Dir) ->
{ok, Names} = file:list_dir(Dir), {ok, Names} = file:list_dir(Dir),
[list_to_atom(Name) || Name <- Names, filelib:is_dir(filename:join([Dir, Name]))]. [list_to_atom(Name) || Name <- Names, filelib:is_dir(filename:join([Dir, Name]))].