test: ets table cleanup after cases

This commit is contained in:
JimMoen 2023-07-21 19:42:02 +08:00
parent 4e4b1ac115
commit c393c2e091
No known key found for this signature in database
GPG Key ID: 87A520B4F76BA86D
1 changed files with 16 additions and 8 deletions

View File

@ -30,7 +30,8 @@ t_insert(_) ->
true = emqx_rule_index:insert(<<"sensor/+/#">>, t_insert_2, <<>>, Tab), true = emqx_rule_index:insert(<<"sensor/+/#">>, t_insert_2, <<>>, Tab),
true = emqx_rule_index:insert(<<"sensor/#">>, t_insert_3, <<>>, Tab), true = emqx_rule_index:insert(<<"sensor/#">>, t_insert_3, <<>>, Tab),
?assertEqual(<<"sensor/#">>, get_topic(match(<<"sensor">>, Tab))), ?assertEqual(<<"sensor/#">>, get_topic(match(<<"sensor">>, Tab))),
?assertEqual(t_insert_3, get_id(match(<<"sensor">>, Tab))). ?assertEqual(t_insert_3, get_id(match(<<"sensor">>, Tab))),
true = ets:delete(Tab).
t_match(_) -> t_match(_) ->
Tab = new(), Tab = new(),
@ -40,7 +41,8 @@ t_match(_) ->
?assertMatch( ?assertMatch(
[<<"sensor/#">>, <<"sensor/+/#">>], [<<"sensor/#">>, <<"sensor/+/#">>],
[get_topic(M) || M <- matches(<<"sensor/1">>, Tab)] [get_topic(M) || M <- matches(<<"sensor/1">>, Tab)]
). ),
true = ets:delete(Tab).
t_match2(_) -> t_match2(_) ->
Tab = new(), Tab = new(),
@ -54,7 +56,8 @@ t_match2(_) ->
?assertEqual( ?assertEqual(
false, false,
emqx_rule_index:match(<<"$SYS/broker/zenmq">>, Tab) emqx_rule_index:match(<<"$SYS/broker/zenmq">>, Tab)
). ),
true = ets:delete(Tab).
t_match3(_) -> t_match3(_) ->
Tab = new(), Tab = new(),
@ -77,7 +80,8 @@ t_match3(_) ->
?assertEqual( ?assertEqual(
t_match3_sys, t_match3_sys,
get_id(match(<<"$SYS/a/b/c">>, Tab)) get_id(match(<<"$SYS/a/b/c">>, Tab))
). ),
true = ets:delete(Tab).
t_match4(_) -> t_match4(_) ->
Tab = new(), Tab = new(),
@ -93,7 +97,8 @@ t_match4(_) ->
?assertEqual( ?assertEqual(
[<<"/#">>, <<"/+/a/b/c">>], [<<"/#">>, <<"/+/a/b/c">>],
[get_topic(M) || M <- matches(<<"/0/a/b/c">>, Tab)] [get_topic(M) || M <- matches(<<"/0/a/b/c">>, Tab)]
). ),
true = ets:delete(Tab).
t_match5(_) -> t_match5(_) ->
Tab = new(), Tab = new(),
@ -114,21 +119,24 @@ t_match5(_) ->
?assertEqual( ?assertEqual(
[<<"#">>, <<T/binary, "/#">>, <<T/binary, "/+">>], [<<"#">>, <<T/binary, "/#">>, <<T/binary, "/+">>],
[get_topic(M) || M <- matches(<<T/binary, "/1">>, Tab)] [get_topic(M) || M <- matches(<<T/binary, "/1">>, Tab)]
). ),
true = ets:delete(Tab).
t_match6(_) -> t_match6(_) ->
Tab = new(), Tab = new(),
T = <<"a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z">>, T = <<"a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z">>,
W = <<"+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/#">>, W = <<"+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/#">>,
emqx_rule_index:insert(W, ID = t_match6, <<>>, Tab), emqx_rule_index:insert(W, ID = t_match6, <<>>, Tab),
?assertEqual(ID, get_id(match(T, Tab))). ?assertEqual(ID, get_id(match(T, Tab))),
true = ets:delete(Tab).
t_match7(_) -> t_match7(_) ->
Tab = new(), Tab = new(),
T = <<"a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z">>, T = <<"a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z">>,
W = <<"a/+/c/+/e/+/g/+/i/+/k/+/m/+/o/+/q/+/s/+/u/+/w/+/y/+/#">>, W = <<"a/+/c/+/e/+/g/+/i/+/k/+/m/+/o/+/q/+/s/+/u/+/w/+/y/+/#">>,
emqx_rule_index:insert(W, t_match7, <<>>, Tab), emqx_rule_index:insert(W, t_match7, <<>>, Tab),
?assertEqual(W, get_topic(match(T, Tab))). ?assertEqual(W, get_topic(match(T, Tab))),
true = ets:delete(Tab).
new() -> new() ->
ets:new(?MODULE, [public, ordered_set, {write_concurrency, true}]). ets:new(?MODULE, [public, ordered_set, {write_concurrency, true}]).