Skip to content

Commit

Permalink
fix(test): adapt to emqx 5.0 master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Oct 28, 2021
1 parent 41855ec commit 594bcd2
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 14 deletions.
3 changes: 3 additions & 0 deletions include/emqtt.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,7 @@

-define(PACKET(Type), #mqtt_packet{header = #mqtt_packet_header{type = Type}}).

-define(catch_error(Error, Exp),
try (Exp) catch error:Error -> ok end).

-endif.
6 changes: 3 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
{profiles,
[{test,
[{deps,
[{meck, "0.9.2"},
{emqx, {git_subdir, "https://github.com/qzhuyan/emqx", {branch, "dev/william/5.0-quic-support-2"}, "apps/emqx"}},
{emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {branch, "hocon"}}}
[ {meck, "0.9.2"}
, {emqx, {git_subdir, "https://github.com/emqx/emqx", {branch, "master"}, "apps/emqx"}}
, {proper, "1.4.0"}
]},
{erl_opts, [debug_info]},
%% Define `TEST' in emqx to get empty `foreign_refereced_schema_apps'
Expand Down
4 changes: 2 additions & 2 deletions test/emqtt_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ groups() ->
retain_as_publish_test]}].

init_per_suite(Config) ->
emqx_ct_helpers:start_apps([]),
ok = emqtt_test_lib:start_emqx(),
Config.

end_per_suite(_Config) ->
emqx_ct_helpers:stop_apps([]).
emqtt_test_lib:stop_emqx().

receive_messages(Count) ->
receive_messages(Count, []).
Expand Down
1 change: 0 additions & 1 deletion test/emqtt_frame_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("emqx_ct_helpers/include/emqx_ct.hrl").

%%-define(PROPTEST(F), ?assert(proper:quickcheck(F()))).
-define(PROPTEST(F), ?assert(proper:quickcheck(F(), [{to_file, user}]))).
Expand Down
10 changes: 8 additions & 2 deletions test/emqtt_props_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@

-include("emqtt.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("emqx_ct_helpers/include/emqx_ct.hrl").

all() -> emqx_ct:all(?MODULE).
all() -> emqx_common_test_helpers:all(?MODULE).

init_per_suite(Config) ->
emqtt_test_lib:ensure_test_module(emqx_common_test_helpers),
Config.

end_per_suite(_Config) ->
ok.

t_id(_) ->
foreach_prop(
Expand Down
4 changes: 3 additions & 1 deletion test/emqtt_quic_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

-include_lib("eunit/include/eunit.hrl").

all() -> emqx_ct:all(?MODULE).
all() -> emqx_common_test_helpers:all(?MODULE).

init_per_suite(Config) ->
emqtt_test_lib:start_emqx(),
application:ensure_all_started(quicer),
Config.

end_per_suite(_) ->
emqtt_test_lib:stop_emqx(),
ok.

t_quic_sock(Config) ->
Expand Down
4 changes: 2 additions & 2 deletions test/emqtt_request_response_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
-include_lib("common_test/include/ct.hrl").

init_per_suite(Config) ->
emqx_ct_helpers:start_apps([]),
ok = emqtt_test_lib:start_emqx(),
Config.

end_per_suite(_Config) ->
emqx_ct_helpers:stop_apps([]).
emqtt_test_lib:stop_emqx().

all() ->
[request_response].
Expand Down
12 changes: 9 additions & 3 deletions test/emqtt_sock_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@

-include_lib("eunit/include/eunit.hrl").

all() -> emqx_ct:all(?MODULE).
all() -> emqx_common_test_helpers:all(?MODULE).

init_per_suite(Config) ->
emqtt_test_lib:ensure_test_module(emqx_common_test_helpers),
Config.

end_per_suite(_Config) ->
ok.
%%--------------------------------------------------------------------
%% Test cases
%%--------------------------------------------------------------------

t_tcp_sock(_) ->
Server = tcp_server:start_link(4000),
{ok, Sock} = emqtt_sock:connect("127.0.0.1", 4000, [], 3000),
Server = tcp_server:start_link(4001),
{ok, Sock} = emqtt_sock:connect("127.0.0.1", 4001, [], 3000),
send_and_recv_with(Sock),
ok = emqtt_sock:close(Sock),
ok = tcp_server:stop(Server).
Expand Down
47 changes: 47 additions & 0 deletions test/emqtt_test_lib.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------

-module(emqtt_test_lib).

-export([ start_emqx/0
, stop_emqx/0
, ensure_test_module/1
]).

-spec start_emqx() -> ok.
start_emqx() ->
ensure_test_module(emqx_common_test_helpers),
emqx_common_test_helpers:start_apps([]),
ok.

-spec stop_emqx() -> ok.
stop_emqx() ->
ensure_test_module(emqx_common_test_helpers),
emqx_common_test_helpers:stop_apps([]).

-spec ensure_test_module(M::atom()) -> ok.
ensure_test_module(M) ->
false == code:is_loaded(M) andalso
compile_emqx_test_module(M).

-spec compile_emqx_test_module(M::atom()) -> ok.
compile_emqx_test_module(M) ->
EmqxDir = code:lib_dir(emqx),
EmqttDir = code:lib_dir(emqtt),
MFilename= filename:join([EmqxDir, "test", M]),
OutDir = filename:join([EmqttDir, "test"]),
{ok, _} = compile:file(MFilename, [{outdir, OutDir}]),
ok.

0 comments on commit 594bcd2

Please sign in to comment.