From 31098d6c67b3c1b2252c32cb81d9d50be5489d25 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 6 Dec 2022 19:03:32 +0100 Subject: [PATCH] test: fix bridge api tests, metrics is now a separate api --- .../test/emqx_bridge_mqtt_SUITE.erl | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/apps/emqx_bridge/test/emqx_bridge_mqtt_SUITE.erl b/apps/emqx_bridge/test/emqx_bridge_mqtt_SUITE.erl index 84152efc6..c907205f1 100644 --- a/apps/emqx_bridge/test/emqx_bridge_mqtt_SUITE.erl +++ b/apps/emqx_bridge/test/emqx_bridge_mqtt_SUITE.erl @@ -313,9 +313,10 @@ t_ingress_mqtt_bridge_with_rules(_) -> ), %% and also the rule should be matched, with matched + 1: {ok, 200, Rule1} = request(get, uri(["rules", RuleId]), []), + {ok, 200, Metrics} = request(get, uri(["rules", RuleId, "metrics"]), []), + ?assertMatch(#{<<"id">> := RuleId}, jsx:decode(Rule1)), ?assertMatch( #{ - <<"id">> := RuleId, <<"metrics">> := #{ <<"matched">> := 1, <<"passed">> := 1, @@ -332,8 +333,9 @@ t_ingress_mqtt_bridge_with_rules(_) -> <<"actions.failed.unknown">> := 0 } }, - jsx:decode(Rule1) + jsx:decode(Metrics) ), + %% we also check if the actions of the rule is triggered ?assertMatch( #{ @@ -429,24 +431,29 @@ t_egress_mqtt_bridge_with_rules(_) -> timer:sleep(100), emqx:publish(emqx_message:make(RuleTopic, Payload2)), {ok, 200, Rule1} = request(get, uri(["rules", RuleId]), []), - #{ - <<"id">> := RuleId, - <<"metrics">> := #{ - <<"matched">> := 1, - <<"passed">> := 1, - <<"failed">> := 0, - <<"failed.exception">> := 0, - <<"failed.no_result">> := 0, - <<"matched.rate">> := _, - <<"matched.rate.max">> := _, - <<"matched.rate.last5m">> := _, - <<"actions.total">> := 1, - <<"actions.success">> := 1, - <<"actions.failed">> := 0, - <<"actions.failed.out_of_service">> := 0, - <<"actions.failed.unknown">> := 0 - } - } = jsx:decode(Rule1), + ?assertMatch(#{<<"id">> := RuleId, <<"name">> := _}, jsx:decode(Rule1)), + {ok, 200, Metrics} = request(get, uri(["rules", RuleId, "metrics"]), []), + ?assertMatch( + #{ + <<"metrics">> := #{ + <<"matched">> := 1, + <<"passed">> := 1, + <<"failed">> := 0, + <<"failed.exception">> := 0, + <<"failed.no_result">> := 0, + <<"matched.rate">> := _, + <<"matched.rate.max">> := _, + <<"matched.rate.last5m">> := _, + <<"actions.total">> := 1, + <<"actions.success">> := 1, + <<"actions.failed">> := 0, + <<"actions.failed.out_of_service">> := 0, + <<"actions.failed.unknown">> := 0 + } + }, + jsx:decode(Metrics) + ), + %% we should receive a message on the "remote" broker, with specified topic ?assert( receive