From fe3b13b7661f2201b2eaeab0e1a94433bb9b898e Mon Sep 17 00:00:00 2001 From: superCharge Date: Sat, 26 Aug 2023 17:11:41 +0800 Subject: [PATCH] add test case for tcp_proxy Signed-off-by: superCharge --- test/testcases/kmesh.json | 5 +- .../conf/test_conf.json | 93 +++++++++++++++++++ ..._test_tcp_proxy_weight_cluster_function.sh | 62 +++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/conf/test_conf.json create mode 100644 test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/oe_test_tcp_proxy_weight_cluster_function.sh diff --git a/test/testcases/kmesh.json b/test/testcases/kmesh.json index 0ad1a9a..f94994a 100644 --- a/test/testcases/kmesh.json +++ b/test/testcases/kmesh.json @@ -14,7 +14,10 @@ "name": "oe_test_route_function" }, { - "name": "oe_test_service_function" + "name": "oe_test_service_function" + }, + { + "name": "oe_test_tcp_proxy_weight_cluster_function" } ] } diff --git a/test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/conf/test_conf.json b/test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/conf/test_conf.json new file mode 100644 index 0000000..02eb6b5 --- /dev/null +++ b/test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/conf/test_conf.json @@ -0,0 +1,93 @@ +{ + "staticResources":{ + "versionInfo":"v2", + "listenerConfigs":[ + { + "apiStatus":"UPDATE", + "name":"127.0.0.1_9081", + "address":{ + "port":9563, + "ipv4":16777343 + }, + "filterChains":[ + { + "filterChainMatch":{ + "transportProtocol":"raw_buffer", + "applicationProtocols":[ + "http/1.0", + "http/1.1", + "h2c" + ] + }, + "filters":[ + { + "name":"envoy.filters.network.tcp_proxy", + "tcp_proxy": { + "weighted_clusters": { + "clusters": [ + { + "name": "outbound|9080|v1|details.default.svc.cluster.local", + "weight": 80 + }, + { + "name": "outbound|9080|v2|details.default.svc.cluster.local", + "weight": 20 + } + ] + } + } + } + ] + } + ] + } + ], + "clusterConfigs":[ + { + "apiStatus":"UPDATE", + "name":"outbound|9080|v1|details.default.svc.cluster.local", + "connectTimeout":10, + "lb_policy":"ROUND_ROBIN", + "loadAssignment":{ + "clusterName":"outbound|9080|v1|details.default.svc.cluster.local", + "endpoints":[ + { + "lbEndpoints":[ + { + "address":{ + "port":51756, + "ipv4":16777343 + } + } + ], + "loadBalancingWeight":1 + } + ] + } + }, + { + "apiStatus":"UPDATE", + "name":"outbound|9080|v2|details.default.svc.cluster.local", + "connectTimeout":10, + "lb_policy":"ROUND_ROBIN", + "loadAssignment":{ + "clusterName":"outbound|9080|v2|details.default.svc.cluster.local", + "endpoints":[ + { + "lbEndpoints":[ + { + "address":{ + "port":57388, + "ipv4":16777343 + } + } + ], + "loadBalancingWeight":1 + } + ] + } + } + ] + } +} + diff --git a/test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/oe_test_tcp_proxy_weight_cluster_function.sh b/test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/oe_test_tcp_proxy_weight_cluster_function.sh new file mode 100644 index 0000000..528ed9d --- /dev/null +++ b/test/testcases/kmesh/oe_test_tcp_proxy_weight_cluster_function/oe_test_tcp_proxy_weight_cluster_function.sh @@ -0,0 +1,62 @@ +#!/usr/bin/bash + +source ${OET_PATH}/libs/locallibs/common_lib.sh +source ../libs/common.sh + +CURRENT_PATH=$(pwd) + +function pre_test() { + LOG_INFO "Start environmental preparation." + + env_init + + LOG_INFO "End of environmental preparation!" +} + +function run_test() { + LOG_INFO "Start testing..." + + # exits the shell when $? is not 0 + set -e + + # start fortio server 11466 + # start fortio server 11488 + start_fortio_server -http-port 127.0.0.1:11466 -echo-server-default-params="header=server:1" + start_fortio_server -http-port 127.0.0.1:11488 -echo-server-default-params="header=server:2" + + # start kmesh-daemon + start_kmesh + + # use kmesh-cmd load conf and check conf load ok + load_kmesh_config + + # curl 100 times, Server: 1 and Server: 2 should be 8:2 + # the traffic is not completely regular,Server: 1 belong 70%-90% and Server: 2 belong 10%-30% + for ((i=0;i<100;i++)) + do + curl -v http://127.0.0.1:23333 >> tmp_trace.log 2>&1 + done + + a=`grep -c 'Server: 1' tmp_trace.log` + b=`grep -c 'Server: 2' tmp_trace.log` + if [ $a -gt 70 ]&&[ $a -lt 90 ]&&[ $b -lt 30 ]&&[ $b -gt 10 ];then + result=0 + else + result=1 + fi + CHECK_RESULT $result 0 0 "bad tcp weighted cluster select" + + LOG_INFO "Finish test!" +} + +function post_test() { + LOG_INFO "start environment cleanup." + + cleanup + + LOG_INFO "Finish environment cleanup!" +} + +main "$@" + + -- Gitee