ci: update testcases for message-expiry-interval

This commit is contained in:
Shawn 2024-01-30 15:45:50 +08:00
parent 9f22c2c455
commit 206af96a33
1 changed files with 39 additions and 7 deletions

View File

@ -141,18 +141,50 @@ t_undefined_headers(_) ->
Msg2 = emqx_message:set_header(c, 3, Msg), Msg2 = emqx_message:set_header(c, 3, Msg),
?assertEqual(3, emqx_message:get_header(c, Msg2)). ?assertEqual(3, emqx_message:get_header(c, Msg2)).
t_is_expired(_) -> t_is_expired_1(_) ->
test_msg_expired_property(?MODULE).
t_is_expired_2(_) ->
%% if the 'Message-Expiry-Interval' property is set, the message_expiry_interval should be ignored
try
emqx_config:put(
maps:from_list([{list_to_atom(Root), #{}} || Root <- emqx_zone_schema:roots()])
),
emqx_config:put_zone_conf(?MODULE, [mqtt, message_expiry_interval], timer:seconds(10)),
test_msg_expired_property(?MODULE)
after
emqx_config:erase_all()
end.
t_is_expired_3(_) ->
try
emqx_config:put(
maps:from_list([{list_to_atom(Root), #{}} || Root <- emqx_zone_schema:roots()])
),
emqx_config:put_zone_conf(?MODULE, [mqtt, message_expiry_interval], 100),
Msg = emqx_message:make(<<"clientid">>, <<"topic">>, <<"payload">>), Msg = emqx_message:make(<<"clientid">>, <<"topic">>, <<"payload">>),
?assertNot(emqx_message:is_expired(Msg, ?MODULE)), ?assertNot(emqx_message:is_expired(Msg, ?MODULE)),
timer:sleep(120),
?assert(emqx_message:is_expired(Msg, ?MODULE))
after
emqx_config:erase_all()
end.
test_msg_expired_property(Zone) ->
Msg = emqx_message:make(<<"clientid">>, <<"topic">>, <<"payload">>),
?assertNot(emqx_message:is_expired(Msg, Zone)),
Msg1 = emqx_message:set_headers(#{properties => #{'Message-Expiry-Interval' => 1}}, Msg), Msg1 = emqx_message:set_headers(#{properties => #{'Message-Expiry-Interval' => 1}}, Msg),
timer:sleep(500), timer:sleep(500),
?assertNot(emqx_message:is_expired(Msg1, ?MODULE)), ?assertNot(emqx_message:is_expired(Msg1, Zone)),
timer:sleep(600), timer:sleep(600),
?assert(emqx_message:is_expired(Msg1, ?MODULE)), ?assert(emqx_message:is_expired(Msg1, Zone)).
t_update_expired(_) ->
Msg = emqx_message:make(<<"clientid">>, <<"topic">>, <<"payload">>),
timer:sleep(1000), timer:sleep(1000),
Msg = emqx_message:update_expiry(Msg), ?assertEqual(Msg, emqx_message:update_expiry(Msg)),
Msg2 = emqx_message:update_expiry(Msg1), Msg1 = emqx_message:set_headers(#{properties => #{'Message-Expiry-Interval' => 1}}, Msg),
Props = emqx_message:get_header(properties, Msg2), Props = emqx_message:get_header(properties, emqx_message:update_expiry(Msg1)),
?assertEqual(1, maps:get('Message-Expiry-Interval', Props)). ?assertEqual(1, maps:get('Message-Expiry-Interval', Props)).
% t_to_list(_) -> % t_to_list(_) ->