test: fix float point number compare

This commit is contained in:
Zaiming (Stone) Shi 2022-04-06 21:09:10 +02:00
parent 243a30dacb
commit d1e773d83c
1 changed files with 9 additions and 5 deletions

View File

@ -377,11 +377,15 @@ t_reset_metrics(_Config) ->
end end
|| _ <- lists:seq(1,10)], || _ <- lists:seq(1,10)],
emqx_rule_metrics:reset_metrics(Id), emqx_rule_metrics:reset_metrics(Id),
?assertEqual(#{exception => 0,failed => 0, Expected = #{exception => 0, failed => 0, matched => 0, no_result => 0,
matched => 0,no_result => 0,passed => 0, passed => 0, speed => 0.0, speed_last5m => 0.0, speed_max => 0},
speed => 0.0,speed_last5m => 0.0,speed_max => 0}, Got = emqx_rule_metrics:get_rule_metrics(Id),
emqx_rule_metrics:get_rule_metrics(Id)), %% use == instead of =:=, so that 0 and 0.0 are compared equal
?assertEqual(#{failed => 0,success => 0,taken => 0}, case Expected == Got of
true -> ok;
false -> ?assertEqual(Expected, Got)
end,
?assertEqual(#{failed => 0, success => 0, taken => 0},
emqx_rule_metrics:get_action_metrics(ResId)), emqx_rule_metrics:get_action_metrics(ResId)),
emqtt:stop(Client), emqtt:stop(Client),
emqx_rule_registry:remove_rule(Id), emqx_rule_registry:remove_rule(Id),