Skip to content

Commit

Permalink
Merge pull request #39 from cabol/build_and_test_fixes
Browse files Browse the repository at this point in the history
[#38] – Fix tests to use rebar3 directly instead of call ct_run
  • Loading branch information
cabol authored Feb 16, 2017
2 parents 456474f + d56d5a5 commit 65b6132
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 70 deletions.
69 changes: 41 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
REBAR = $(shell which rebar3 || echo ./rebar3)
REBAR = $(shell which rebar3)

ifdef REBAR_PROFILE
PROFILE = $(REBAR_PROFILE)
else
PROFILE = default
endif

BUILD_PATH = ./_build/$(PROFILE)/lib/*/ebin

CONFIG ?= test/test.config
EPMD_PROC_NUM = $(shell ps -ef | grep epmd | grep -v "grep")

CT_OPTS = -cover test/cover.spec -erl_args -config ${CONFIG}
CT_SUITES = ebus_task_SUITE \
ebus_ps_local_SUITE \
ebus_ps_SUITE \
ebus_handler_SUITE \
ebus_dist_SUITE
.PHONY: all check_rebar compile clean distclean dialyzer tests shell edoc

.PHONY: all compile clean distclean dialyze tests shell doc
all: check_rebar compile

all: compile
check_rebar:
ifeq ($(REBAR),)
ifeq ($(wildcard rebar3),)
curl -O https://s3.amazonaws.com/rebar3/rebar3
chmod a+x rebar3
./rebar3 update
$(eval REBAR=./rebar3)
else
$(eval REBAR=./rebar3)
endif
endif

compile:
compile: check_rebar
$(REBAR) compile

clean:
clean: check_rebar
rm -rf ebin/* test/*.beam logs log
$(REBAR) clean

distclean: clean
$(REBAR) clean --all
rm -rf _build logs log doc
rm -rf _build logs log doc *.dump *_plt *.crashdump priv

dialyze:
dialyzer: check_rebar
$(REBAR) dialyzer

tests: compile
mkdir -p logs
ct_run -dir test -suite $(CT_SUITES) -pa $(BUILD_PATH) -logdir logs $(CT_OPTS)
check_epmd:
ifeq ($(EPMD_PROC_NUM),)
epmd&
@echo " ---> Started epmd!"
endif

test: check_rebar check_epmd
$(REBAR) ct --name ct@127.0.0.1
$(REBAR) cover
rm -rf test/*.beam

local_test: check_rebar check_epmd
$(REBAR) ct --suite=test/ebus_task_SUITE,test/ebus_ps_SUITE,test/ebus_ps_local_SUITE,test/ebus_handler_SUITE
$(REBAR) cover
rm -rf test/*.beam

dist_test: check_rebar check_epmd
$(REBAR) ct --name ct@127.0.0.1 --suite=test/ebus_dist_SUITE
$(REBAR) cover
rm -rf test/*.beam

shell: compile
erl -pa $(BUILD_PATH) -s ebus -config ${CONFIG}
shell: check_rebar
$(REBAR) shell

doc:
edoc: check_rebar
$(REBAR) edoc
73 changes: 63 additions & 10 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
%% == Erlang Compiler ==

{erl_opts, [debug_info, warnings_as_errors]}.
{erl_opts, [
debug_info,
warnings_as_errors,
warn_unused_vars,
ewarn_export_all,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_bif_clash,
warn_unused_record,
warn_deprecated_function,
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
warn_untyped_record
]}.

%% == Cover ==

Expand All @@ -10,14 +26,51 @@

{deps, []}.

%% == Profiles ==
%% == Common Test ==

{ct_compile_opts, [
debug_info,
warnings_as_errors,
warn_unused_vars,
ewarn_export_all,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_bif_clash,
warn_unused_record,
warn_deprecated_function,
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
warn_untyped_record
]}.

{ct_opts, [
{sys_config, ["test/test.config"]}
]}.

%% == EDoc ==

{edoc_opts, []}.

%% == Shell ==

{shell, [{apps, [ebus]}]}.

%% == Dialyzer ==

{profiles, [
{debug, [
{erl_opts, [debug_info, warnings_as_errors]},
{deps, [
{recon, {git, "https://github.com/ferd/recon.git", {branch, "master"}}},
{eper, {git, "https://github.com/massemanet/eper.git", {tag, "0.97.1"}}}
]}
]}
{dialyzer, [
{warnings, [
race_conditions,
no_return,
unmatched_returns,
error_handling
]},
{plt_apps, top_level_deps},
{plt_extra_apps, []},
{plt_location, local},
{plt_prefix, "ebus"},
{base_plt_location, "."},
{base_plt_prefix, "ebus"}
]}.
9 changes: 6 additions & 3 deletions src/ebus.app.src
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{application, ebus, [
{description, "ErlBus: Erlang Message Event Bus"},
{vsn, "0.2.0"},
{description, "Erlang Message Event Bus"},
{vsn, "0.2.1"},
{id, "ebus"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib]},
{applications, [
kernel,
stdlib
]},
{mod, {ebus, []}},
{env, []},
{maintainers, ["Carlos Andres Bolanos"]},
Expand Down
62 changes: 33 additions & 29 deletions test/ebus_dist_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ all() -> [t_pubsub, t_dispatch].

init_per_suite(Config) ->
ebus:start(),
Nodes = start_slaves(),
Nodes = start_slaves([a, b, c, d]),
[{nodes, Nodes} | Config].

end_per_suite(Config) ->
ebus:stop(),
stop_slaves([a, b, c, d]),
Config.

%%%===================================================================
Expand Down Expand Up @@ -157,10 +158,9 @@ t_dispatch(Config) ->
L1 = r_process_messages(NodePidL),

% dispatch global with default dispatch_fun
lists:foreach(
fun(_) -> ok = ebus:dispatch("foo", <<"M2">>, [{scope, global}]) end,
lists:seq(1, 500)
),
lists:foreach(fun(_) ->
ok = ebus:dispatch("foo", <<"M2">>, [{scope, global}])
end, lists:seq(1, 500)),
timer:sleep(1500),

% check remote processes received message
Expand All @@ -173,13 +173,11 @@ t_dispatch(Config) ->
[S1 | _] = ebus:subscribers("foo"),
MsgsS1 = length(ebus_proc:r_messages(S1)),
Fun = fun([H | _]) -> H end,
lists:foreach(
fun(_) ->
ok = ebus:dispatch(
"foo", <<"M3">>, [{scope, global}, {dispatch_fun, Fun}]
)
end, lists:seq(1, 100)
),
lists:foreach(fun(_) ->
ok = ebus:dispatch(
"foo", <<"M3">>,
[{scope, global}, {dispatch_fun, Fun}])
end, lists:seq(1, 100)),
timer:sleep(1500),
MsgsS11 = MsgsS1 + 100,
MsgsS11 = length(ebus_proc:r_messages(S1)),
Expand All @@ -191,14 +189,13 @@ t_dispatch(Config) ->
%% Internal functions
%%==============================================================================

start_slaves() ->
Nodes = [a, b, c, d],
start_slaves(Nodes, []).
start_slaves(Slaves) ->
start_slaves(Slaves, []).

start_slaves([], Acc) -> Acc;
start_slaves([], Acc) ->
lists:usort(Acc);
start_slaves([Node | T], Acc) ->
ErlFlags = "-pa ../../_build/default/lib/*/ebin " ++
"-config ../../test/test.config",
ErlFlags = "-pa ../../lib/*/ebin -config ../../../../test/test.config",
{ok, HostNode} = ct_slave:start(Node, [
{kill_if_fail, true},
{monitor_master, true},
Expand All @@ -207,29 +204,36 @@ start_slaves([Node | T], Acc) ->
{startup_functions, [{ebus, start, []}]},
{erl_flags, ErlFlags}
]),
ct:print("\e[32m ---> Node ~p [OK] \e[0m", [HostNode]),
ct:print("\e[36m ---> Node ~p \e[32m[OK] \e[0m", [HostNode]),
pong = net_adm:ping(HostNode),
start_slaves(T, [HostNode | Acc]).

stop_slaves(Slaves) ->
stop_slaves(Slaves, []).

stop_slaves([], Acc) ->
lists:usort(Acc);
stop_slaves([Node | T], Acc) ->
{ok, Name} = ct_slave:stop(Node),
ct:print("\e[36m ---> Node ~p \e[31m[STOPPED] \e[0m", [Name]),
pang = net_adm:ping(Node),
stop_slaves(T, [Node | Acc]).

spawn_remote_pids(RemoteNodes) ->
{ResL, _} = rpc:multicall(
RemoteNodes, ebus_proc, spawn_timer_fun, [infinity]
),
lists:zip(RemoteNodes, ResL).

sub_remote_pids(RemotePids, Topic) ->
lists:foreach(
fun({Node, Pid}) ->
ok = rpc:call(Node, ebus, sub, [Pid, Topic])
end, RemotePids
).
lists:foreach(fun({Node, Pid}) ->
ok = rpc:call(Node, ebus, sub, [Pid, Topic])
end, RemotePids).

unsub_remote_pids(RemotePids, Topic) ->
lists:foreach(
fun({Node, Pid}) ->
ok = rpc:call(Node, ebus, unsub, [Pid, Topic])
end, RemotePids
).
lists:foreach(fun({Node, Pid}) ->
ok = rpc:call(Node, ebus, unsub, [Pid, Topic])
end, RemotePids).

r_process_messages(RemotePids) ->
[ebus_proc:r_messages(Pid) || {_, Pid} <- RemotePids].
1 change: 1 addition & 0 deletions test/ebus_handler_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
all() -> [t_handler, t_callback_handler].

init_per_suite(Config) ->
ebus:stop(),
ebus:start(),
Config.

Expand Down

0 comments on commit 65b6132

Please sign in to comment.