test: expand EE mysql bridge test with toxiproxy
This commit is contained in:
parent
96bff1d32e
commit
eb62192838
|
@ -13,6 +13,8 @@ services:
|
||||||
- 8474:8474
|
- 8474:8474
|
||||||
- 8086:8086
|
- 8086:8086
|
||||||
- 8087:8087
|
- 8087:8087
|
||||||
|
- 13306:3306
|
||||||
|
- 13307:3307
|
||||||
command:
|
command:
|
||||||
- "-host=0.0.0.0"
|
- "-host=0.0.0.0"
|
||||||
- "-config=/config/toxiproxy.json"
|
- "-config=/config/toxiproxy.json"
|
||||||
|
|
|
@ -10,5 +10,17 @@
|
||||||
"listen": "0.0.0.0:8087",
|
"listen": "0.0.0.0:8087",
|
||||||
"upstream": "influxdb_tls:8086",
|
"upstream": "influxdb_tls:8086",
|
||||||
"enabled": true
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mysql_tcp",
|
||||||
|
"listen": "0.0.0.0:3306",
|
||||||
|
"upstream": "mysql:3306",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mysql_tls",
|
||||||
|
"listen": "0.0.0.0:3307",
|
||||||
|
"upstream": "mysql-tls:3306",
|
||||||
|
"enabled": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
toxiproxy
|
||||||
influxdb
|
influxdb
|
||||||
kafka
|
kafka
|
||||||
mongo
|
mongo
|
||||||
|
|
|
@ -63,22 +63,24 @@ groups() ->
|
||||||
].
|
].
|
||||||
|
|
||||||
init_per_group(tcp, Config0) ->
|
init_per_group(tcp, Config0) ->
|
||||||
MysqlHost = os:getenv("MYSQL_TCP_HOST", "mysql"),
|
MysqlHost = os:getenv("MYSQL_TCP_HOST", "toxiproxy"),
|
||||||
MysqlPort = list_to_integer(os:getenv("MYSQL_TCP_PORT", "3306")),
|
MysqlPort = list_to_integer(os:getenv("MYSQL_TCP_PORT", "3306")),
|
||||||
Config = [
|
Config = [
|
||||||
{mysql_host, MysqlHost},
|
{mysql_host, MysqlHost},
|
||||||
{mysql_port, MysqlPort},
|
{mysql_port, MysqlPort},
|
||||||
{enable_tls, false}
|
{enable_tls, false},
|
||||||
|
{proxy_name, "mysql_tcp"}
|
||||||
| Config0
|
| Config0
|
||||||
],
|
],
|
||||||
common_init(Config);
|
common_init(Config);
|
||||||
init_per_group(tls, Config0) ->
|
init_per_group(tls, Config0) ->
|
||||||
MysqlHost = os:getenv("MYSQL_TLS_HOST", "mysql-tls"),
|
MysqlHost = os:getenv("MYSQL_TLS_HOST", "toxiproxy"),
|
||||||
MysqlPort = list_to_integer(os:getenv("MYSQL_TLS_PORT", "3306")),
|
MysqlPort = list_to_integer(os:getenv("MYSQL_TLS_PORT", "3307")),
|
||||||
Config = [
|
Config = [
|
||||||
{mysql_host, MysqlHost},
|
{mysql_host, MysqlHost},
|
||||||
{mysql_port, MysqlPort},
|
{mysql_port, MysqlPort},
|
||||||
{enable_tls, true}
|
{enable_tls, true},
|
||||||
|
{proxy_name, "mysql_tls"}
|
||||||
| Config0
|
| Config0
|
||||||
],
|
],
|
||||||
common_init(Config);
|
common_init(Config);
|
||||||
|
@ -95,6 +97,9 @@ init_per_group(_Group, Config) ->
|
||||||
|
|
||||||
end_per_group(Group, Config) when Group =:= tcp; Group =:= tls ->
|
end_per_group(Group, Config) when Group =:= tcp; Group =:= tls ->
|
||||||
connect_and_drop_table(Config),
|
connect_and_drop_table(Config),
|
||||||
|
ProxyHost = ?config(proxy_host, Config),
|
||||||
|
ProxyPort = ?config(proxy_port, Config),
|
||||||
|
emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
|
||||||
ok;
|
ok;
|
||||||
end_per_group(_Group, _Config) ->
|
end_per_group(_Group, _Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
@ -107,16 +112,18 @@ end_per_suite(_Config) ->
|
||||||
ok = emqx_common_test_helpers:stop_apps([emqx_bridge, emqx_conf]),
|
ok = emqx_common_test_helpers:stop_apps([emqx_bridge, emqx_conf]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_per_testcase(_Testcase, Config0) ->
|
init_per_testcase(_Testcase, Config) ->
|
||||||
Config = [{mysql_direct_pid, connect_direct_mysql(Config0)} | Config0],
|
% Config = [{mysql_direct_pid, connect_direct_mysql(Config0)} | Config0],
|
||||||
catch clear_table(Config),
|
connect_and_clear_table(Config),
|
||||||
delete_bridge(Config),
|
delete_bridge(Config),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_testcase(_Testcase, Config) ->
|
end_per_testcase(_Testcase, Config) ->
|
||||||
catch clear_table(Config),
|
ProxyHost = ?config(proxy_host, Config),
|
||||||
DirectPid = ?config(mysql_direct_pid, Config),
|
ProxyPort = ?config(proxy_port, Config),
|
||||||
mysql:stop(DirectPid),
|
emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
|
||||||
|
connect_and_clear_table(Config),
|
||||||
|
ok = snabbkaffe:stop(),
|
||||||
delete_bridge(Config),
|
delete_bridge(Config),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -130,6 +137,10 @@ common_init(Config0) ->
|
||||||
MysqlPort = ?config(mysql_port, Config0),
|
MysqlPort = ?config(mysql_port, Config0),
|
||||||
case emqx_common_test_helpers:is_tcp_server_available(MysqlHost, MysqlPort) of
|
case emqx_common_test_helpers:is_tcp_server_available(MysqlHost, MysqlPort) of
|
||||||
true ->
|
true ->
|
||||||
|
% Setup toxiproxy
|
||||||
|
ProxyHost = os:getenv("PROXY_HOST", "toxiproxy"),
|
||||||
|
ProxyPort = list_to_integer(os:getenv("PROXY_PORT", "8474")),
|
||||||
|
emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
|
||||||
% Ensure EE bridge module is loaded
|
% Ensure EE bridge module is loaded
|
||||||
_ = application:load(emqx_ee_bridge),
|
_ = application:load(emqx_ee_bridge),
|
||||||
_ = emqx_ee_bridge:module_info(),
|
_ = emqx_ee_bridge:module_info(),
|
||||||
|
@ -142,7 +153,9 @@ common_init(Config0) ->
|
||||||
[
|
[
|
||||||
{mysql_config, MysqlConfig},
|
{mysql_config, MysqlConfig},
|
||||||
{mysql_bridge_type, BridgeType},
|
{mysql_bridge_type, BridgeType},
|
||||||
{mysql_name, Name}
|
{mysql_name, Name},
|
||||||
|
{proxy_host, ProxyHost},
|
||||||
|
{proxy_port, ProxyPort}
|
||||||
| Config0
|
| Config0
|
||||||
],
|
],
|
||||||
Config;
|
Config;
|
||||||
|
@ -255,14 +268,16 @@ connect_and_drop_table(Config) ->
|
||||||
ok = mysql:query(DirectPid, ?SQL_DROP_TABLE),
|
ok = mysql:query(DirectPid, ?SQL_DROP_TABLE),
|
||||||
mysql:stop(DirectPid).
|
mysql:stop(DirectPid).
|
||||||
|
|
||||||
% These funs expects a connection to already exist
|
connect_and_clear_table(Config) ->
|
||||||
clear_table(Config) ->
|
DirectPid = connect_direct_mysql(Config),
|
||||||
DirectPid = ?config(mysql_direct_pid, Config),
|
ok = mysql:query(DirectPid, ?SQL_DELETE),
|
||||||
ok = mysql:query(DirectPid, ?SQL_DELETE).
|
mysql:stop(DirectPid).
|
||||||
|
|
||||||
get_payload(Config) ->
|
connect_and_get_payload(Config) ->
|
||||||
DirectPid = ?config(mysql_direct_pid, Config),
|
DirectPid = connect_direct_mysql(Config),
|
||||||
mysql:query(DirectPid, ?SQL_SELECT).
|
Result = mysql:query(DirectPid, ?SQL_SELECT),
|
||||||
|
mysql:stop(DirectPid),
|
||||||
|
Result.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Testcases
|
%% Testcases
|
||||||
|
@ -284,7 +299,7 @@ t_setup_via_config_and_publish(Config) ->
|
||||||
),
|
),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, [<<"payload">>], [[Val]]},
|
{ok, [<<"payload">>], [[Val]]},
|
||||||
get_payload(Config)
|
connect_and_get_payload(Config)
|
||||||
),
|
),
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
|
@ -319,7 +334,7 @@ t_setup_via_http_api_and_publish(Config) ->
|
||||||
),
|
),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, [<<"payload">>], [[Val]]},
|
{ok, [<<"payload">>], [[Val]]},
|
||||||
get_payload(Config)
|
connect_and_get_payload(Config)
|
||||||
),
|
),
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
|
@ -330,3 +345,25 @@ t_setup_via_http_api_and_publish(Config) ->
|
||||||
end
|
end
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_get_status(Config) ->
|
||||||
|
?assertMatch(
|
||||||
|
{ok, _},
|
||||||
|
create_bridge(Config)
|
||||||
|
),
|
||||||
|
ProxyPort = ?config(proxy_port, Config),
|
||||||
|
ProxyHost = ?config(proxy_host, Config),
|
||||||
|
ProxyName = ?config(proxy_name, Config),
|
||||||
|
|
||||||
|
Name = ?config(mysql_name, Config),
|
||||||
|
BridgeType = ?config(mysql_bridge_type, Config),
|
||||||
|
ResourceID = emqx_bridge_resource:resource_id(BridgeType, Name),
|
||||||
|
|
||||||
|
?assertEqual({ok, connected}, emqx_resource_manager:health_check(ResourceID)),
|
||||||
|
emqx_common_test_helpers:with_failure(down, ProxyName, ProxyHost, ProxyPort, fun() ->
|
||||||
|
?assertMatch(
|
||||||
|
{ok, Status} when Status =:= disconnected orelse Status =:= connecting,
|
||||||
|
emqx_resource_manager:health_check(ResourceID)
|
||||||
|
)
|
||||||
|
end),
|
||||||
|
ok.
|
||||||
|
|
|
@ -92,9 +92,11 @@ for dep in ${CT_DEPS}; do
|
||||||
erlang24)
|
erlang24)
|
||||||
FILES+=( '.ci/docker-compose-file/docker-compose.yaml' )
|
FILES+=( '.ci/docker-compose-file/docker-compose.yaml' )
|
||||||
;;
|
;;
|
||||||
|
toxiproxy)
|
||||||
|
FILES+=( '.ci/docker-compose-file/docker-compose-toxiproxy.yaml' )
|
||||||
|
;;
|
||||||
influxdb)
|
influxdb)
|
||||||
FILES+=( '.ci/docker-compose-file/docker-compose-toxiproxy.yaml'
|
FILES+=( '.ci/docker-compose-file/docker-compose-influxdb-tcp.yaml'
|
||||||
'.ci/docker-compose-file/docker-compose-influxdb-tcp.yaml'
|
|
||||||
'.ci/docker-compose-file/docker-compose-influxdb-tls.yaml' )
|
'.ci/docker-compose-file/docker-compose-influxdb-tls.yaml' )
|
||||||
;;
|
;;
|
||||||
mongo)
|
mongo)
|
||||||
|
|
Loading…
Reference in New Issue