diff --git a/.ci/fvt_tests/http_server/src/http_server.erl b/.ci/fvt_tests/http_server/src/http_server.erl index b66b72939..4b1981de4 100644 --- a/.ci/fvt_tests/http_server/src/http_server.erl +++ b/.ci/fvt_tests/http_server/src/http_server.erl @@ -1,36 +1,41 @@ -module(http_server). --import(minirest, [ return/0 - , return/1 - ]). +-import(minirest, [ + return/0, + return/1 +]). --export([ start/0 - , stop/0 - ]). +-export([ + start/0, + stop/0 +]). --rest_api(#{ name => get_counter - , method => 'GET' - , path => "/counter" - , func => get_counter - , descr => "Check counter" - }). --rest_api(#{ name => add_counter - , method => 'POST' - , path => "/counter" - , func => add_counter - , descr => "Counter plus one" - }). +-rest_api(#{ + name => get_counter, + method => 'GET', + path => "/counter", + func => get_counter, + descr => "Check counter" +}). +-rest_api(#{ + name => add_counter, + method => 'POST', + path => "/counter", + func => add_counter, + descr => "Counter plus one" +}). --export([ get_counter/2 - , add_counter/2 - ]). +-export([ + get_counter/2, + add_counter/2 +]). start() -> application:ensure_all_started(minirest), ets:new(relup_test_message, [named_table, public]), Handlers = [{"/", minirest:handler(#{modules => [?MODULE]})}], Dispatch = [{"/[...]", minirest, Handlers}], - minirest:start_http(?MODULE, #{socket_opts => [inet, {port, 8080}]}, Dispatch). + minirest:start_http(?MODULE, #{socket_opts => [inet, {port, 7077}]}, Dispatch). stop() -> ets:delete(relup_test_message), @@ -39,12 +44,12 @@ stop() -> get_counter(_Binding, _Params) -> return({ok, ets:info(relup_test_message, size)}). -add_counter(_Binding, Params) -> +add_counter(_Binding, Params) -> case lists:keymember(<<"payload">>, 1, Params) of - true -> + true -> {value, {<<"id">>, ID}, Params1} = lists:keytake(<<"id">>, 1, Params), ets:insert(relup_test_message, {ID, Params1}); - _ -> + _ -> ok end, return(). diff --git a/.ci/fvt_tests/relup.lux b/.ci/fvt_tests/relup.lux index 9e67dfd63..a6de27e94 100644 --- a/.ci/fvt_tests/relup.lux +++ b/.ci/fvt_tests/relup.lux @@ -16,7 +16,7 @@ ???Eshell ???> !http_server:start(). - ?Start http_server listener on 8080 successfully. + ?Start http_server listener on 7077 successfully. ?ok ?> @@ -27,9 +27,6 @@ ?SH-PROMPT !cd emqx - !sed -i 's|listener.wss.external[ \t]*=.*|listener.wss.external = 8085|g' etc/emqx.conf - !sed -i '/emqx_telemetry/d' data/loaded_plugins - !./bin/emqx start ?EMQ X .* is started successfully! ?SH-PROMPT @@ -53,24 +50,27 @@ !./bin/emqx_ctl cluster status """??? - Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'], - stopped_nodes => []} + Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],stopped_nodes => []} """ ?SH-PROMPT - !./bin/emqx_ctl resources create 'web_hook' -i 'resource:691c29ba' -c '{"url": "http://127.0.0.1:8080/counter", "method": "POST"}' - ?created + ## create a webhook data bridge with id "my_webhook" + !curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/bridges' -X 'POST' -H 'Content-Type: application/json' --data-binary '{"name":"my_webhook","method":"post","url":"http://127.0.0.1:7077/counter","headers":{"content-type":"application/json"},"pool_size":4,"enable_pipelining":100,"connect_timeout":"5s","request_timeout":"5s","max_retries":3,"type":"webhook","ssl":{"enable":false,"verify":"verify_none"}}' | jq '.status' + ?connected ?SH-PROMPT - !./bin/emqx_ctl rules create 'SELECT * FROM "t/#"' '[{"name":"data_to_webserver", "params": {"$$resource": "resource:691c29ba"}}]' - ?created + + ## create a rule that uses the webhook as action, the rule id = "rule_edsy" + !curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/rules' -X 'POST' -H 'Content-Type: application/json' --data-binary '{"id":"rule_edsy","sql":"SELECT\n *\nFROM\n \"t/#\"","actions":["webhook:my_webhook"]}' | jq '.id' + ?rule_edsy ?SH-PROMPT [shell emqx] - !./bin/emqx_ctl resources list - ?691c29ba + ## verify the bridges and rules are sync to the other node + !curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/bridges/webhook:my_webhook' -X 'GET' -H 'Content-Type: application/json' | jq '.name' + ?my_webhook ?SH-PROMPT - !./bin/emqx_ctl rules list - ?691c29ba + !curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/rules/rule_edsy' -X 'GET' -H 'Content-Type: application/json' | jq '.id' + ?rule_edsy ?SH-PROMPT [shell bench] @@ -116,15 +116,10 @@ !./bin/emqx_ctl cluster status """??? - Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'], - stopped_nodes => []} + Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],stopped_nodes => []} """ ?SH-PROMPT - !./bin/emqx_ctl plugins list | grep emqx_management - ?Plugin\(emqx_management.*active=true\) - ?SH-PROMPT - [shell emqx2] !echo "" > log/emqx.log.1 ?SH-PROMPT @@ -162,15 +157,10 @@ !./bin/emqx_ctl cluster status """??? - Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'], - stopped_nodes => []} + Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],stopped_nodes => []} """ ?SH-PROMPT - !./bin/emqx_ctl plugins list | grep emqx_management - ?Plugin\(emqx_management.*active=true\) - ?SH-PROMPT - ## We don't guarantee not to lose a single message! ## So even if we received 290~300 messages, we consider it as success [shell bench] @@ -187,6 +177,11 @@ ?\{"data":(29[0-9])|(300),"code":0\} ?SH-PROMPT + ## The /counter API is provided by .ci/fvt_test/http_server + !curl http://127.0.0.1:7077/counter + ?\{"data":(29[0-9])|(300),"code":0\} + ?SH-PROMPT + [shell emqx2] !cat log/emqx.log.1 |grep -v 691c29ba |tail -n 100 -error