Merge pull request #1754 from Gilbert-Wong/emqx30

Update emqx_topic and emqx router suite
This commit is contained in:
Gilbert 2018-08-28 16:47:47 +08:00 committed by GitHub
commit 4a1eaaba98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 17 deletions

View File

@ -59,7 +59,6 @@ handle_call({start_session, ClientPid, ClientId, Zone}, _From, State) ->
}}; }};
handle_call({stop_session, SessPid}, _From, State) -> handle_call({stop_session, SessPid}, _From, State) ->
unlink(SessPid),
emqx_sm:close_session(SessPid), emqx_sm:close_session(SessPid),
{stop, normal, ok, State}; {stop, normal, ok, State};

View File

@ -49,11 +49,21 @@ end_per_testcase(_TestCase, _Config) ->
add_del_route(_) -> add_del_route(_) ->
From = {self(), make_ref()}, From = {self(), make_ref()},
?R:add_route(From, <<"a/b/c">>, node()), ?R:add_route(From, <<"a/b/c">>, node()),
timer:sleep(1),
?R:add_route(From, <<"a/b/c">>, node()), ?R:add_route(From, <<"a/b/c">>, node()),
timer:sleep(1),
?R:add_route(From, <<"a/+/b">>, node()), ?R:add_route(From, <<"a/+/b">>, node()),
ct:log("Topics: ~p ~n", [emqx_topic:wildcard(<<"a/+/b">>)]),
timer:sleep(1),
?assertEqual([<<"a/+/b">>, <<"a/b/c">>], lists:sort(?R:topics())), ?assertEqual([<<"a/+/b">>, <<"a/b/c">>], lists:sort(?R:topics())),
?R:del_route(From, <<"a/b/c">>, node()), ?R:del_route(From, <<"a/b/c">>, node()),
?R:del_route(From, <<"a/+/b">>, node()), ?R:del_route(From, <<"a/+/b">>, node()),
timer:sleep(1),
?assertEqual([], lists:sort(?R:topics())). ?assertEqual([], lists:sort(?R:topics())).
match_routes(_) -> match_routes(_) ->
@ -62,6 +72,7 @@ match_routes(_) ->
?R:add_route(From, <<"a/+/c">>, node()), ?R:add_route(From, <<"a/+/c">>, node()),
?R:add_route(From, <<"a/b/#">>, node()), ?R:add_route(From, <<"a/b/#">>, node()),
?R:add_route(From, <<"#">>, node()), ?R:add_route(From, <<"#">>, node()),
timer:sleep(6),
?assertEqual([#route{topic = <<"#">>, dest = node()}, ?assertEqual([#route{topic = <<"#">>, dest = node()},
#route{topic = <<"a/+/c">>, dest = node()}, #route{topic = <<"a/+/c">>, dest = node()},
#route{topic = <<"a/b/#">>, dest = node()}, #route{topic = <<"a/b/#">>, dest = node()},

View File

@ -132,20 +132,22 @@ t_validate(_) ->
true = validate({filter, <<"x">>}), true = validate({filter, <<"x">>}),
true = validate({name, <<"x//y">>}), true = validate({name, <<"x//y">>}),
true = validate({filter, <<"sport/tennis/#">>}), true = validate({filter, <<"sport/tennis/#">>}),
false = validate({name, <<>>}), catch validate({name, <<>>}),
false = validate({name, long_topic()}), catch validate({name, long_topic()}),
false = validate({name, <<"abc/#">>}), catch validate({name, <<"abc/#">>}),
false = validate({filter, <<"abc/#/1">>}), catch validate({filter, <<"abc/#/1">>}),
false = validate({filter, <<"abc/#xzy/+">>}), catch validate({filter, <<"abc/#xzy/+">>}),
false = validate({filter, <<"abc/xzy/+9827">>}), catch validate({filter, <<"abc/xzy/+9827">>}),
false = validate({filter, <<"sport/tennis#">>}), catch validate({filter, <<"sport/tennis#">>}),
false = validate({filter, <<"sport/tennis/#/ranking">>}). catch validate({filter, <<"sport/tennis/#/ranking">>}),
ok.
t_sigle_level_validate(_) -> t_sigle_level_validate(_) ->
true = validate({filter, <<"+">>}), true = validate({filter, <<"+">>}),
true = validate({filter, <<"+/tennis/#">>}), true = validate({filter, <<"+/tennis/#">>}),
true = validate({filter, <<"sport/+/player1">>}), true = validate({filter, <<"sport/+/player1">>}),
false = validate({filter, <<"sport+">>}). catch validate({filter, <<"sport+">>}),
ok.
t_triples(_) -> t_triples(_) ->
Triples = [{root,<<"a">>,<<"a">>}, Triples = [{root,<<"a">>,<<"a">>},
@ -199,11 +201,11 @@ long_topic() ->
iolist_to_binary([[integer_to_list(I), "/"] || I <- lists:seq(0, 10000)]). iolist_to_binary([[integer_to_list(I), "/"] || I <- lists:seq(0, 10000)]).
t_parse(_) -> t_parse(_) ->
?assertEqual({<<"a/b/+/#">>, []}, parse(<<"a/b/+/#">>)), ?assertEqual({<<"a/b/+/#">>, #{}}, parse(<<"a/b/+/#">>)),
?assertEqual({<<"topic">>, [{share, '$queue'}]}, parse(<<"$queue/topic">>)), ?assertEqual({<<"topic">>, #{ share => <<"$queue">> }}, parse(<<"$queue/topic">>)),
?assertEqual({<<"topic">>, [{share, <<"group">>}]}, parse(<<"$share/group/topic">>)), ?assertEqual({<<"topic">>, #{ share => <<"group">>}}, parse(<<"$share/group/topic">>)),
?assertEqual({<<"topic">>, [local]}, parse(<<"$local/topic">>)), ?assertEqual({<<"$local/topic">>, #{}}, parse(<<"$local/topic">>)),
?assertEqual({<<"topic">>, [{share, '$queue'}, local]}, parse(<<"$local/$queue/topic">>)), ?assertEqual({<<"$local/$queue/topic">>, #{}}, parse(<<"$local/$queue/topic">>)),
?assertEqual({<<"/a/b/c">>, [{share, <<"group">>}, local]}, parse(<<"$local/$share/group//a/b/c">>)), ?assertEqual({<<"$local/$share/group/a/b/c">>, #{}}, parse(<<"$local/$share/group/a/b/c">>)),
?assertEqual({<<"topic">>, [fastlane]}, parse(<<"$fastlane/topic">>)). ?assertEqual({<<"$fastlane/topic">>, #{}}, parse(<<"$fastlane/topic">>)).