test(channel): fix flaky test

```
%%% emqx_channel_SUITE ==> t_handle_kicked_publish_will_msg: FAILED
%%% emqx_channel_SUITE ==> will_message_not_published
```

The problem was that the whole generated message was compared for
equality when receiving the will message, but the timestamp may be
different at publishing time...
This commit is contained in:
Thales Macedo Garitezi 2023-05-31 11:29:48 -03:00
parent 77c9eda036
commit 189e2c87be
1 changed files with 13 additions and 3 deletions

View File

@ -885,14 +885,24 @@ t_handle_kicked_publish_will_msg(_) ->
Self = self(), Self = self(),
ok = meck:expect(emqx_broker, publish, fun(M) -> Self ! {pub, M} end), ok = meck:expect(emqx_broker, publish, fun(M) -> Self ! {pub, M} end),
Msg = emqx_message:make(test, <<"will_topic">>, <<"will_payload">>), ClientId = test,
WillTopic = <<"will_topic">>,
WillPayload = <<"will_payload">>,
Msg = emqx_message:make(ClientId, WillTopic, WillPayload),
{shutdown, kicked, ok, ?DISCONNECT_PACKET(?RC_ADMINISTRATIVE_ACTION), _} = emqx_channel:handle_call( {shutdown, kicked, ok, ?DISCONNECT_PACKET(?RC_ADMINISTRATIVE_ACTION), _} = emqx_channel:handle_call(
kick, channel(#{will_msg => Msg}) kick, channel(#{will_msg => Msg})
), ),
receive receive
{pub, Msg} -> ok {pub, RecMsg} ->
after 10_000 -> exit(will_message_not_published) ?assertEqual(ClientId, RecMsg#message.from, #{msg => Msg}),
?assertEqual(WillTopic, RecMsg#message.topic, #{msg => Msg}),
?assertEqual(WillPayload, RecMsg#message.payload, #{msg => Msg}),
ok
after 5_000 ->
ct:pal("expected message: ~p", [Msg]),
ct:pal("~p mailbox: ~p", [?LINE, process_info(self(), messages)]),
exit(will_message_not_published)
end. end.
t_handle_call_discard(_) -> t_handle_call_discard(_) ->