From 5b509768ed94a36f3e825deaffabfd8d6213295b Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 14:42:03 +0800 Subject: [PATCH 01/46] add test cases --- .github/workflows/build.yml | 2 +- t/pycases/cases/test_base.py | 33 ++++++++++++++ t/pycases/requirements.txt | 7 +++ t/pycases/runtest.py | 84 ++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 t/pycases/cases/test_base.py create mode 100644 t/pycases/requirements.txt create mode 100644 t/pycases/runtest.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c46c97f95aa0..bf17d3b5c7f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: platform: [ubuntu-18.04] - os_name: [linux_openresty, linux_tengine, linux_apisix_master_luarocks, linux_apisix_current_luarocks, linux_openresty_mtls] + os_name: [linux_apisix_integrationtest] include: - platform: macos-latest os_name: osx_openresty diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py new file mode 100644 index 000000000000..ef933d864c82 --- /dev/null +++ b/t/pycases/cases/test_base.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +import sys,os,time,requests,json + +def setup_module(): + global headers + headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} + print("setup_module") + +def teardown_module(): + print("teardown_module") + + +def test_01(): + cfgdata = { + "uri": "/apisix/status", + "upstream": { + "type": "roundrobin", + "nodes": { + "39.97.63.215:80": 1 + } + } +} + r = requests.put("http://127.0.0.1:9080/apisix/admin/routes/1", json=cfgdata,headers=headers ) + r = json.loads(r.content) + assert r["action"] == "set" + + r = requests.get("http://127.0.0.1:9080/apisix/admin/routes/1", headers=headers ) + r = json.loads(r.content) + assert r["action"] == "get" + + r = requests.get("http://127.0.0.1:9080/apisix/status") + assert r.status_code == 200 \ No newline at end of file diff --git a/t/pycases/requirements.txt b/t/pycases/requirements.txt new file mode 100644 index 000000000000..9853a3338db7 --- /dev/null +++ b/t/pycases/requirements.txt @@ -0,0 +1,7 @@ +pytest==4.0.1 +pytest-metadata==1.7.0 +pytest-html==1.14.2 +futures==3.2.0 +requests==2.21.0 +flaky==3.4.0 +attrs==19.1.0 diff --git a/t/pycases/runtest.py b/t/pycases/runtest.py new file mode 100644 index 000000000000..142ea9ebbd4f --- /dev/null +++ b/t/pycases/runtest.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- + +import random,subprocess,shutil +import time, datetime +import sys,os +import json +import re +import base64 + +def cur_file_dir(): + return os.path.split(os.path.realpath(__file__))[0] + +def install_packages(casepath): + new_packages=["pytest","pytest-html","futures"] + for case_file_path in glob.glob(r'%s/*.py'%casepath): + with open(case_file_path) as fh: + rule = re.compile('from\s+(.+?)\s+import|import\s+(.*)') + result=rule.findall(fh.read()) + if len(result)>0: + for i in range(len(result)): + for j in range(len(result[i])): + for k in result[i][j].split(","): + if k.strip()!='': + if k.strip().find('.')!=-1: + new_packages.append(k.strip().split(".")[0]) + else: + new_packages.append(k.strip()) + new_packages=list(set(new_packages)) + # print new_packages + self_packages=set() + self_packages.update(sys.builtin_module_names) + for dirName in os.listdir(r'%s\Lib'%py_path): + if os.path.isdir('%s\\Lib\\'%py_path+dirName): + self_packages.add(dirName) + elif dirName.endswith(".py"): + self_packages.add(os.path.splitext(dirName)[0]) + + cmd=r"pip list" # two format : zope.interface (4.2.0) or altgraph 0.16.1 + pipe1 = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE,stderr=subprocess.PIPE) + content = pipe1.stdout.read() + rule = re.compile('([^()\s]+)\s+\(?\d') + # print rule.findall(content) + self_packages.update(rule.findall(content)) + + other=get_speciallibs() + self_packages.update(other) + for i in new_packages: + if i not in self_packages and 'publicfunc' not in i: + print u'%s发现新的依赖库%s,正在安装!'%(i,casepath) + cmd=r"%s\Scripts\pip.exe install %s"%(py_path,i) # 用-U安装时可能会出错 + pipe = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE) + pipe.wait() + # print pipe.read() + # else: + # print u"没有新的依赖库" + +def runcase(casedirpath): + + updatepip = "curl https://bootstrap.pypa.io/get-pip.py | python" + setupcmd = "pip install -r %s/requirements.txt"%cur_file_dir() + exc_case_cmd='pytest --force-flaky --max-runs=3 --no-flaky-report -q "%s" --html="%s/result.html" --self-contained-html > "%s/result.log"'%(casedirpath,casedirpath,casedirpath) + exc_case_cmd2='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" > "%s/result.log"'%(casedirpath,casedirpath) + + #r_exc_case_cmd = subprocess.Popen(updatepip, stderr=subprocess.PIPE,shell=True) + #r_exc_case_cmd.wait() + #err = r_exc_case_cmd.stderr.read() + #print(err) + + r_exc_case_cmd = subprocess.Popen(setupcmd, stderr=subprocess.PIPE,shell=True) + r_exc_case_cmd.wait() + err = r_exc_case_cmd.stderr.read() + + r_exc_case_cmd = subprocess.Popen(exc_case_cmd2, stderr=subprocess.PIPE,shell=True) + r_exc_case_cmd.wait() + err = r_exc_case_cmd.stderr.read() + + shutil.rmtree(cur_file_dir()+r'/.pytest_cache') + shutil.rmtree(casedirpath+r'/__pycache__') + + + +casepath = cur_file_dir()+"/cases" +runcase(casepath) \ No newline at end of file From 8c524cb680e7bdfa93f294d9cba409f8ea17fa49 Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 14:46:21 +0800 Subject: [PATCH 02/46] add --- .travis/linux_apisix_integrationtest.sh | 157 ++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100755 .travis/linux_apisix_integrationtest.sh diff --git a/.travis/linux_apisix_integrationtest.sh b/.travis/linux_apisix_integrationtest.sh new file mode 100755 index 000000000000..ba5679a8b088 --- /dev/null +++ b/.travis/linux_apisix_integrationtest.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -ex + +export_or_prefix() { + export OPENRESTY_PREFIX="/usr/local/openresty-debug" +} + +create_lua_deps() { + echo "Create lua deps cache" + + make deps + luarocks install luacov-coveralls --tree=deps --local > build.log 2>&1 || (cat build.log && exit 1) + + sudo rm -rf build-cache/deps + sudo cp -r deps build-cache/ + sudo cp rockspec/apisix-master-0.rockspec build-cache/ +} + +before_install() { + sudo cpanm --notest Test::Nginx >build.log 2>&1 || (cat build.log && exit 1) + docker pull redis:3.0-alpine + docker run --rm -itd -p 6379:6379 --name apisix_redis redis:3.0-alpine + docker run --rm -itd -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8888:8888 -p 9999:9999 mendhak/http-https-echo + # Runs Keycloak version 10.0.2 with inbuilt policies for unit tests + docker run --rm -itd -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=123456 -p 8090:8080 -p 8443:8443 sshniro/keycloak-apisix + # spin up kafka cluster for tests (1 zookeper and 1 kafka instance) + docker pull bitnami/zookeeper:3.6.0 + docker pull bitnami/kafka:latest + docker network create kafka-net --driver bridge + docker run --name zookeeper-server -d -p 2181:2181 --network kafka-net -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper:3.6.0 + docker run --name kafka-server1 -d --network kafka-net -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper-server:2181 -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 -p 9092:9092 -e KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true bitnami/kafka:latest + docker pull bitinit/eureka + docker run --name eureka -d -p 8761:8761 --env ENVIRONMENT=apisix --env spring.application.name=apisix-eureka --env server.port=8761 --env eureka.instance.ip-address=127.0.0.1 --env eureka.client.registerWithEureka=true --env eureka.client.fetchRegistry=false --env eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8761/eureka/ bitinit/eureka + sleep 5 + docker exec -i kafka-server1 /opt/bitnami/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper-server:2181 --replication-factor 1 --partitions 1 --topic test2 +} + +do_install() { + export_or_prefix + + wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add - + sudo apt-get -y update --fix-missing + sudo apt-get -y install software-properties-common + sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" + + sudo apt-get update + sudo apt-get install openresty-debug lua5.1 liblua5.1-0-dev + + wget https://github.com/luarocks/luarocks/archive/v2.4.4.tar.gz + tar -xf v2.4.4.tar.gz + cd luarocks-2.4.4 + ./configure --prefix=/usr > build.log 2>&1 || (cat build.log && exit 1) + make build > build.log 2>&1 || (cat build.log && exit 1) + sudo make install > build.log 2>&1 || (cat build.log && exit 1) + cd .. + rm -rf luarocks-2.4.4 + + sudo luarocks install luacheck > build.log 2>&1 || (cat build.log && exit 1) + + ./utils/install-etcd.sh + + if [ ! -f "build-cache/apisix-master-0.rockspec" ]; then + create_lua_deps + + else + src=`md5sum rockspec/apisix-master-0.rockspec | awk '{print $1}'` + src_cp=`md5sum build-cache/apisix-master-0.rockspec | awk '{print $1}'` + if [ "$src" = "$src_cp" ]; then + echo "Use lua deps cache" + sudo cp -r build-cache/deps ./ + else + create_lua_deps + fi + fi + + # sudo apt-get install tree -y + # tree deps + + git clone https://github.com/iresty/test-nginx.git test-nginx + make utils + + git clone https://github.com/apache/openwhisk-utilities.git .travis/openwhisk-utilities + cp .travis/ASF* .travis/openwhisk-utilities/scancode/ + + ls -l ./ + if [ ! -f "build-cache/grpc_server_example" ]; then + wget https://github.com/iresty/grpc_server_example/releases/download/20200901/grpc_server_example-amd64.tar.gz + tar -xvf grpc_server_example-amd64.tar.gz + mv grpc_server_example build-cache/ + fi + + if [ ! -f "build-cache/proto/helloworld.proto" ]; then + if [ ! -f "grpc_server_example/main.go" ]; then + git clone https://github.com/iresty/grpc_server_example.git grpc_server_example + fi + + cd grpc_server_example/ + mv proto/ ../build-cache/ + cd .. + fi + + if [ ! -f "build-cache/grpcurl" ]; then + wget https://github.com/api7/grpcurl/releases/download/20200314/grpcurl-amd64.tar.gz + tar -xvf grpcurl-amd64.tar.gz + mv grpcurl build-cache/ + fi +} + +script() { + export_or_prefix + export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH + openresty -V + sudo service etcd stop + mkdir -p ~/etcd-data + etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 & + etcdctl version + sleep 5 + + cd t/pycases/ + sudo python runtest.py + +} + + +case_opt=$1 +shift + +case ${case_opt} in +before_install) + before_install "$@" + ;; +do_install) + do_install "$@" + ;; +script) + script "$@" + ;; + + +esac From 573e77af01920d91e20016c36221ed5d4fc229c7 Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 14:51:39 +0800 Subject: [PATCH 03/46] add --- .../linux_apisix_integrationtest_runner.sh | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100755 .travis/linux_apisix_integrationtest_runner.sh diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh new file mode 100755 index 000000000000..ba5679a8b088 --- /dev/null +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -ex + +export_or_prefix() { + export OPENRESTY_PREFIX="/usr/local/openresty-debug" +} + +create_lua_deps() { + echo "Create lua deps cache" + + make deps + luarocks install luacov-coveralls --tree=deps --local > build.log 2>&1 || (cat build.log && exit 1) + + sudo rm -rf build-cache/deps + sudo cp -r deps build-cache/ + sudo cp rockspec/apisix-master-0.rockspec build-cache/ +} + +before_install() { + sudo cpanm --notest Test::Nginx >build.log 2>&1 || (cat build.log && exit 1) + docker pull redis:3.0-alpine + docker run --rm -itd -p 6379:6379 --name apisix_redis redis:3.0-alpine + docker run --rm -itd -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8888:8888 -p 9999:9999 mendhak/http-https-echo + # Runs Keycloak version 10.0.2 with inbuilt policies for unit tests + docker run --rm -itd -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=123456 -p 8090:8080 -p 8443:8443 sshniro/keycloak-apisix + # spin up kafka cluster for tests (1 zookeper and 1 kafka instance) + docker pull bitnami/zookeeper:3.6.0 + docker pull bitnami/kafka:latest + docker network create kafka-net --driver bridge + docker run --name zookeeper-server -d -p 2181:2181 --network kafka-net -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper:3.6.0 + docker run --name kafka-server1 -d --network kafka-net -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper-server:2181 -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 -p 9092:9092 -e KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true bitnami/kafka:latest + docker pull bitinit/eureka + docker run --name eureka -d -p 8761:8761 --env ENVIRONMENT=apisix --env spring.application.name=apisix-eureka --env server.port=8761 --env eureka.instance.ip-address=127.0.0.1 --env eureka.client.registerWithEureka=true --env eureka.client.fetchRegistry=false --env eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8761/eureka/ bitinit/eureka + sleep 5 + docker exec -i kafka-server1 /opt/bitnami/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper-server:2181 --replication-factor 1 --partitions 1 --topic test2 +} + +do_install() { + export_or_prefix + + wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add - + sudo apt-get -y update --fix-missing + sudo apt-get -y install software-properties-common + sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" + + sudo apt-get update + sudo apt-get install openresty-debug lua5.1 liblua5.1-0-dev + + wget https://github.com/luarocks/luarocks/archive/v2.4.4.tar.gz + tar -xf v2.4.4.tar.gz + cd luarocks-2.4.4 + ./configure --prefix=/usr > build.log 2>&1 || (cat build.log && exit 1) + make build > build.log 2>&1 || (cat build.log && exit 1) + sudo make install > build.log 2>&1 || (cat build.log && exit 1) + cd .. + rm -rf luarocks-2.4.4 + + sudo luarocks install luacheck > build.log 2>&1 || (cat build.log && exit 1) + + ./utils/install-etcd.sh + + if [ ! -f "build-cache/apisix-master-0.rockspec" ]; then + create_lua_deps + + else + src=`md5sum rockspec/apisix-master-0.rockspec | awk '{print $1}'` + src_cp=`md5sum build-cache/apisix-master-0.rockspec | awk '{print $1}'` + if [ "$src" = "$src_cp" ]; then + echo "Use lua deps cache" + sudo cp -r build-cache/deps ./ + else + create_lua_deps + fi + fi + + # sudo apt-get install tree -y + # tree deps + + git clone https://github.com/iresty/test-nginx.git test-nginx + make utils + + git clone https://github.com/apache/openwhisk-utilities.git .travis/openwhisk-utilities + cp .travis/ASF* .travis/openwhisk-utilities/scancode/ + + ls -l ./ + if [ ! -f "build-cache/grpc_server_example" ]; then + wget https://github.com/iresty/grpc_server_example/releases/download/20200901/grpc_server_example-amd64.tar.gz + tar -xvf grpc_server_example-amd64.tar.gz + mv grpc_server_example build-cache/ + fi + + if [ ! -f "build-cache/proto/helloworld.proto" ]; then + if [ ! -f "grpc_server_example/main.go" ]; then + git clone https://github.com/iresty/grpc_server_example.git grpc_server_example + fi + + cd grpc_server_example/ + mv proto/ ../build-cache/ + cd .. + fi + + if [ ! -f "build-cache/grpcurl" ]; then + wget https://github.com/api7/grpcurl/releases/download/20200314/grpcurl-amd64.tar.gz + tar -xvf grpcurl-amd64.tar.gz + mv grpcurl build-cache/ + fi +} + +script() { + export_or_prefix + export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH + openresty -V + sudo service etcd stop + mkdir -p ~/etcd-data + etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 & + etcdctl version + sleep 5 + + cd t/pycases/ + sudo python runtest.py + +} + + +case_opt=$1 +shift + +case ${case_opt} in +before_install) + before_install "$@" + ;; +do_install) + do_install "$@" + ;; +script) + script "$@" + ;; + + +esac From 40194b62f0acdd8da14d33cbbffac5fd2f49e719 Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 15:08:05 +0800 Subject: [PATCH 04/46] add test cases --- .travis/linux_apisix_integrationtest.sh | 157 ------------------------ t/pycases/runtest.py | 3 +- 2 files changed, 2 insertions(+), 158 deletions(-) delete mode 100755 .travis/linux_apisix_integrationtest.sh diff --git a/.travis/linux_apisix_integrationtest.sh b/.travis/linux_apisix_integrationtest.sh deleted file mode 100755 index ba5679a8b088..000000000000 --- a/.travis/linux_apisix_integrationtest.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -set -ex - -export_or_prefix() { - export OPENRESTY_PREFIX="/usr/local/openresty-debug" -} - -create_lua_deps() { - echo "Create lua deps cache" - - make deps - luarocks install luacov-coveralls --tree=deps --local > build.log 2>&1 || (cat build.log && exit 1) - - sudo rm -rf build-cache/deps - sudo cp -r deps build-cache/ - sudo cp rockspec/apisix-master-0.rockspec build-cache/ -} - -before_install() { - sudo cpanm --notest Test::Nginx >build.log 2>&1 || (cat build.log && exit 1) - docker pull redis:3.0-alpine - docker run --rm -itd -p 6379:6379 --name apisix_redis redis:3.0-alpine - docker run --rm -itd -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8888:8888 -p 9999:9999 mendhak/http-https-echo - # Runs Keycloak version 10.0.2 with inbuilt policies for unit tests - docker run --rm -itd -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=123456 -p 8090:8080 -p 8443:8443 sshniro/keycloak-apisix - # spin up kafka cluster for tests (1 zookeper and 1 kafka instance) - docker pull bitnami/zookeeper:3.6.0 - docker pull bitnami/kafka:latest - docker network create kafka-net --driver bridge - docker run --name zookeeper-server -d -p 2181:2181 --network kafka-net -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper:3.6.0 - docker run --name kafka-server1 -d --network kafka-net -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper-server:2181 -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 -p 9092:9092 -e KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true bitnami/kafka:latest - docker pull bitinit/eureka - docker run --name eureka -d -p 8761:8761 --env ENVIRONMENT=apisix --env spring.application.name=apisix-eureka --env server.port=8761 --env eureka.instance.ip-address=127.0.0.1 --env eureka.client.registerWithEureka=true --env eureka.client.fetchRegistry=false --env eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8761/eureka/ bitinit/eureka - sleep 5 - docker exec -i kafka-server1 /opt/bitnami/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper-server:2181 --replication-factor 1 --partitions 1 --topic test2 -} - -do_install() { - export_or_prefix - - wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add - - sudo apt-get -y update --fix-missing - sudo apt-get -y install software-properties-common - sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" - - sudo apt-get update - sudo apt-get install openresty-debug lua5.1 liblua5.1-0-dev - - wget https://github.com/luarocks/luarocks/archive/v2.4.4.tar.gz - tar -xf v2.4.4.tar.gz - cd luarocks-2.4.4 - ./configure --prefix=/usr > build.log 2>&1 || (cat build.log && exit 1) - make build > build.log 2>&1 || (cat build.log && exit 1) - sudo make install > build.log 2>&1 || (cat build.log && exit 1) - cd .. - rm -rf luarocks-2.4.4 - - sudo luarocks install luacheck > build.log 2>&1 || (cat build.log && exit 1) - - ./utils/install-etcd.sh - - if [ ! -f "build-cache/apisix-master-0.rockspec" ]; then - create_lua_deps - - else - src=`md5sum rockspec/apisix-master-0.rockspec | awk '{print $1}'` - src_cp=`md5sum build-cache/apisix-master-0.rockspec | awk '{print $1}'` - if [ "$src" = "$src_cp" ]; then - echo "Use lua deps cache" - sudo cp -r build-cache/deps ./ - else - create_lua_deps - fi - fi - - # sudo apt-get install tree -y - # tree deps - - git clone https://github.com/iresty/test-nginx.git test-nginx - make utils - - git clone https://github.com/apache/openwhisk-utilities.git .travis/openwhisk-utilities - cp .travis/ASF* .travis/openwhisk-utilities/scancode/ - - ls -l ./ - if [ ! -f "build-cache/grpc_server_example" ]; then - wget https://github.com/iresty/grpc_server_example/releases/download/20200901/grpc_server_example-amd64.tar.gz - tar -xvf grpc_server_example-amd64.tar.gz - mv grpc_server_example build-cache/ - fi - - if [ ! -f "build-cache/proto/helloworld.proto" ]; then - if [ ! -f "grpc_server_example/main.go" ]; then - git clone https://github.com/iresty/grpc_server_example.git grpc_server_example - fi - - cd grpc_server_example/ - mv proto/ ../build-cache/ - cd .. - fi - - if [ ! -f "build-cache/grpcurl" ]; then - wget https://github.com/api7/grpcurl/releases/download/20200314/grpcurl-amd64.tar.gz - tar -xvf grpcurl-amd64.tar.gz - mv grpcurl build-cache/ - fi -} - -script() { - export_or_prefix - export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH - openresty -V - sudo service etcd stop - mkdir -p ~/etcd-data - etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 & - etcdctl version - sleep 5 - - cd t/pycases/ - sudo python runtest.py - -} - - -case_opt=$1 -shift - -case ${case_opt} in -before_install) - before_install "$@" - ;; -do_install) - do_install "$@" - ;; -script) - script "$@" - ;; - - -esac diff --git a/t/pycases/runtest.py b/t/pycases/runtest.py index 142ea9ebbd4f..e38600800e7f 100644 --- a/t/pycases/runtest.py +++ b/t/pycases/runtest.py @@ -61,6 +61,7 @@ def runcase(casedirpath): setupcmd = "pip install -r %s/requirements.txt"%cur_file_dir() exc_case_cmd='pytest --force-flaky --max-runs=3 --no-flaky-report -q "%s" --html="%s/result.html" --self-contained-html > "%s/result.log"'%(casedirpath,casedirpath,casedirpath) exc_case_cmd2='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" > "%s/result.log"'%(casedirpath,casedirpath) + exc_case_cmd3='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" '%(casedirpath) #r_exc_case_cmd = subprocess.Popen(updatepip, stderr=subprocess.PIPE,shell=True) #r_exc_case_cmd.wait() @@ -71,7 +72,7 @@ def runcase(casedirpath): r_exc_case_cmd.wait() err = r_exc_case_cmd.stderr.read() - r_exc_case_cmd = subprocess.Popen(exc_case_cmd2, stderr=subprocess.PIPE,shell=True) + r_exc_case_cmd = subprocess.Popen(exc_case_cmd3, stderr=subprocess.PIPE,shell=True) r_exc_case_cmd.wait() err = r_exc_case_cmd.stderr.read() From 68d790a2273e354102c8dac4921d3869e132a7e5 Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 15:18:28 +0800 Subject: [PATCH 05/46] modify modified: .travis/linux_apisix_integrationtest_runner.sh --- .travis/linux_apisix_integrationtest_runner.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index ba5679a8b088..f4f27274e829 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -133,6 +133,15 @@ script() { etcdctl version sleep 5 + ./bin/apisix start + + #start again --> fial + res=`./bin/apisix start` + if [ "$res" != "APISIX is running..." ]; then + echo "failed: APISIX runs repeatedly" + exit 1 + fi + cd t/pycases/ sudo python runtest.py From 9914c99ed27c70fa15a7914e429e215e6bc95ba1 Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 15:37:34 +0800 Subject: [PATCH 06/46] modified: .travis/linux_apisix_integrationtest_runner.sh modified: t/pycases/runtest.py --- .travis/linux_apisix_integrationtest_runner.sh | 1 + t/pycases/runtest.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index f4f27274e829..618cce459272 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -144,6 +144,7 @@ script() { cd t/pycases/ sudo python runtest.py + pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/pycases/runtest.py b/t/pycases/runtest.py index e38600800e7f..4c98c7e36ad2 100644 --- a/t/pycases/runtest.py +++ b/t/pycases/runtest.py @@ -63,21 +63,21 @@ def runcase(casedirpath): exc_case_cmd2='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" > "%s/result.log"'%(casedirpath,casedirpath) exc_case_cmd3='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" '%(casedirpath) - #r_exc_case_cmd = subprocess.Popen(updatepip, stderr=subprocess.PIPE,shell=True) - #r_exc_case_cmd.wait() - #err = r_exc_case_cmd.stderr.read() + r_exc_case_cmd = subprocess.Popen(updatepip, stderr=subprocess.PIPE,shell=True) + r_exc_case_cmd.wait() + err = r_exc_case_cmd.stderr.read() #print(err) r_exc_case_cmd = subprocess.Popen(setupcmd, stderr=subprocess.PIPE,shell=True) r_exc_case_cmd.wait() err = r_exc_case_cmd.stderr.read() - r_exc_case_cmd = subprocess.Popen(exc_case_cmd3, stderr=subprocess.PIPE,shell=True) - r_exc_case_cmd.wait() - err = r_exc_case_cmd.stderr.read() + #r_exc_case_cmd = subprocess.Popen(exc_case_cmd3, stderr=subprocess.PIPE,shell=True) + #r_exc_case_cmd.wait() + #err = r_exc_case_cmd.stderr.read() - shutil.rmtree(cur_file_dir()+r'/.pytest_cache') - shutil.rmtree(casedirpath+r'/__pycache__') + #shutil.rmtree(cur_file_dir()+r'/.pytest_cache') + #shutil.rmtree(casedirpath+r'/__pycache__') From bc5b67117429946e19335213914630ff2e147cd3 Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 15:45:03 +0800 Subject: [PATCH 07/46] modified: t/pycases/cases/test_base.py --- t/pycases/cases/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index ef933d864c82..63c220fe33ee 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -27,7 +27,7 @@ def test_01(): r = requests.get("http://127.0.0.1:9080/apisix/admin/routes/1", headers=headers ) r = json.loads(r.content) - assert r["action"] == "get" + assert r["action"] == "set" r = requests.get("http://127.0.0.1:9080/apisix/status") assert r.status_code == 200 \ No newline at end of file From a8cbcd4b0b40f11285a7ec7ca3a6e0d01f3499ab Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 16:00:04 +0800 Subject: [PATCH 08/46] modified: t/pycases/cases/test_base.py modified: t/pycases/runtest.py --- t/pycases/cases/test_base.py | 2 +- t/pycases/runtest.py | 60 ++++-------------------------------- 2 files changed, 7 insertions(+), 55 deletions(-) diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 63c220fe33ee..ef933d864c82 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -27,7 +27,7 @@ def test_01(): r = requests.get("http://127.0.0.1:9080/apisix/admin/routes/1", headers=headers ) r = json.loads(r.content) - assert r["action"] == "set" + assert r["action"] == "get" r = requests.get("http://127.0.0.1:9080/apisix/status") assert r.status_code == 200 \ No newline at end of file diff --git a/t/pycases/runtest.py b/t/pycases/runtest.py index 4c98c7e36ad2..c20b253fe114 100644 --- a/t/pycases/runtest.py +++ b/t/pycases/runtest.py @@ -11,67 +11,21 @@ def cur_file_dir(): return os.path.split(os.path.realpath(__file__))[0] -def install_packages(casepath): - new_packages=["pytest","pytest-html","futures"] - for case_file_path in glob.glob(r'%s/*.py'%casepath): - with open(case_file_path) as fh: - rule = re.compile('from\s+(.+?)\s+import|import\s+(.*)') - result=rule.findall(fh.read()) - if len(result)>0: - for i in range(len(result)): - for j in range(len(result[i])): - for k in result[i][j].split(","): - if k.strip()!='': - if k.strip().find('.')!=-1: - new_packages.append(k.strip().split(".")[0]) - else: - new_packages.append(k.strip()) - new_packages=list(set(new_packages)) - # print new_packages - self_packages=set() - self_packages.update(sys.builtin_module_names) - for dirName in os.listdir(r'%s\Lib'%py_path): - if os.path.isdir('%s\\Lib\\'%py_path+dirName): - self_packages.add(dirName) - elif dirName.endswith(".py"): - self_packages.add(os.path.splitext(dirName)[0]) - - cmd=r"pip list" # two format : zope.interface (4.2.0) or altgraph 0.16.1 - pipe1 = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE,stderr=subprocess.PIPE) - content = pipe1.stdout.read() - rule = re.compile('([^()\s]+)\s+\(?\d') - # print rule.findall(content) - self_packages.update(rule.findall(content)) - - other=get_speciallibs() - self_packages.update(other) - for i in new_packages: - if i not in self_packages and 'publicfunc' not in i: - print u'%s发现新的依赖库%s,正在安装!'%(i,casepath) - cmd=r"%s\Scripts\pip.exe install %s"%(py_path,i) # 用-U安装时可能会出错 - pipe = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE) - pipe.wait() - # print pipe.read() - # else: - # print u"没有新的依赖库" - def runcase(casedirpath): - updatepip = "curl https://bootstrap.pypa.io/get-pip.py | python" - setupcmd = "pip install -r %s/requirements.txt"%cur_file_dir() - exc_case_cmd='pytest --force-flaky --max-runs=3 --no-flaky-report -q "%s" --html="%s/result.html" --self-contained-html > "%s/result.log"'%(casedirpath,casedirpath,casedirpath) - exc_case_cmd2='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" > "%s/result.log"'%(casedirpath,casedirpath) - exc_case_cmd3='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" '%(casedirpath) - + requirements = "pip install -r %s/requirements.txt"%cur_file_dir() + r_exc_case_cmd = subprocess.Popen(updatepip, stderr=subprocess.PIPE,shell=True) r_exc_case_cmd.wait() err = r_exc_case_cmd.stderr.read() - #print(err) - r_exc_case_cmd = subprocess.Popen(setupcmd, stderr=subprocess.PIPE,shell=True) + r_exc_case_cmd = subprocess.Popen(requirements, stderr=subprocess.PIPE,shell=True) r_exc_case_cmd.wait() err = r_exc_case_cmd.stderr.read() + #exc_case_cmd='pytest --force-flaky --max-runs=3 --no-flaky-report -q "%s" --html="%s/result.html" --self-contained-html > "%s/result.log"'%(casedirpath,casedirpath,casedirpath) + #exc_case_cmd2='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" > "%s/result.log"'%(casedirpath,casedirpath) + #exc_case_cmd3='pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "%s" '%(casedirpath) #r_exc_case_cmd = subprocess.Popen(exc_case_cmd3, stderr=subprocess.PIPE,shell=True) #r_exc_case_cmd.wait() #err = r_exc_case_cmd.stderr.read() @@ -79,7 +33,5 @@ def runcase(casedirpath): #shutil.rmtree(cur_file_dir()+r'/.pytest_cache') #shutil.rmtree(casedirpath+r'/__pycache__') - - casepath = cur_file_dir()+"/cases" runcase(casepath) \ No newline at end of file From b1ae9e10283a1dea556be9dea640de1e2feadd9c Mon Sep 17 00:00:00 2001 From: idbeta Date: Tue, 22 Sep 2020 16:07:23 +0800 Subject: [PATCH 09/46] modified: .github/workflows/build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf17d3b5c7f5..729227a5b6b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: platform: [ubuntu-18.04] - os_name: [linux_apisix_integrationtest] + os_name: [linux_openresty, linux_tengine, linux_apisix_master_luarocks, linux_apisix_current_luarocks, linux_openresty_mtls, linux_apisix_integrationtest] include: - platform: macos-latest os_name: osx_openresty From f4c25be1d389deadb19b02b66b94d30eab870ff0 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 13:59:52 +0800 Subject: [PATCH 10/46] modified: .github/workflows/build.yml modified: t/pycases/cases/test_base.py modified: t/pycases/requirementst.txt --- .github/workflows/build.yml | 2 +- t/pycases/cases/test_base.py | 69 +++++++++++++++++++++++++++--------- t/pycases/requirements.txt | 4 ++- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 729227a5b6b6..bf17d3b5c7f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: platform: [ubuntu-18.04] - os_name: [linux_openresty, linux_tengine, linux_apisix_master_luarocks, linux_apisix_current_luarocks, linux_openresty_mtls, linux_apisix_integrationtest] + os_name: [linux_apisix_integrationtest] include: - platform: macos-latest os_name: osx_openresty diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index ef933d864c82..8b3e8f79fa34 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -1,33 +1,70 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- -import sys,os,time,requests,json +import sys,os,time,requests,json,subprocess,signal,psutil,grequests + +def killprocesstree(id): + for pid in psutil.pids(): + if psutil.Process(int(pid)).ppid()==id: + psutil.Process(int(pid)).terminate() + psutil.Process(id).terminate() + +def cur_file_dir(): + return os.path.split(os.path.realpath(__file__))[0] + +def geturl(url,times): + start = time.time() + tasks = [] + r = [] + while time.time() - start <= times: + tasks.append(grequests.get(url)) + res = grequests.map(tasks, size=50) + r.extend([i.status_code for i in res]) + return r def setup_module(): - global headers + global headers,nginx_pid,apisixhost + apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} - print("setup_module") + casepath = cur_file_dir() + confpath = casepath + "/nginx.conf" + p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + p.wait() + nginx_pid = p.pid+1 def teardown_module(): - print("teardown_module") + killprocesstree(nginx_pid) +# 单机最少 2 core,用例前后检查点: +# 1. Nginx 里面是否有 error.log 。 +# 2. 运行场景前后进程资源状态值:进程 ID,进程内存。 +# 3. 场景的运行,都应该是对单个 APISIX 服务做测试。 +# ## 场景 1, route +# 1. 添加 /hello 路由,并把它转发到上游 9000 这个端口上,产生 200 应答。 +# 2. 发多个请求(5-10s)-> 200 response。 +# 3. 删除操作 /hello 路由。 +# 4. 发多个请求 (5-10s) -> 404 response。 -def test_01(): - cfgdata = { - "uri": "/apisix/status", +def test_01(): + cfgdata = { + "uri": "/hello", "upstream": { "type": "roundrobin", "nodes": { - "39.97.63.215:80": 1 + "127.0.0.1:9000": 1 } } } - r = requests.put("http://127.0.0.1:9080/apisix/admin/routes/1", json=cfgdata,headers=headers ) - r = json.loads(r.content) - assert r["action"] == "set" + r = requests.put("%s/apisix/admin/routes/1"%apisixhost, json=cfgdata,headers=headers ) + r = json.loads(r.content) + assert r["action"] == "set" + r = requests.get("%s/hello"%apisixhost) + assert r.status_code == 200 and "Hello, World!" in r.content + r = geturl("%s/hello"%apisixhost,10) + assert all(i == 200 for i in r) - r = requests.get("http://127.0.0.1:9080/apisix/admin/routes/1", headers=headers ) - r = json.loads(r.content) - assert r["action"] == "get" + r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) + r = requests.get("%s/hello"%apisixhost) + assert r.status_code == 404 + r = geturl("%s/hello"%apisixhost,10) + assert all(i == 404 for i in r) - r = requests.get("http://127.0.0.1:9080/apisix/status") - assert r.status_code == 200 \ No newline at end of file diff --git a/t/pycases/requirements.txt b/t/pycases/requirements.txt index 9853a3338db7..92677fa27677 100644 --- a/t/pycases/requirements.txt +++ b/t/pycases/requirements.txt @@ -4,4 +4,6 @@ pytest-html==1.14.2 futures==3.2.0 requests==2.21.0 flaky==3.4.0 -attrs==19.1.0 +attrs==19.1.0 +psutil==5.7.2 +gevent==1.1b5 \ No newline at end of file From 6419a3ad8cc7f9ba8bc441a1bf01ef8a9ae4940d Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 14:08:33 +0800 Subject: [PATCH 11/46] modified: t/pycases/requirements.txt --- t/pycases/requirements.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/pycases/requirements.txt b/t/pycases/requirements.txt index 92677fa27677..d2c1c5fcd3a3 100644 --- a/t/pycases/requirements.txt +++ b/t/pycases/requirements.txt @@ -4,6 +4,7 @@ pytest-html==1.14.2 futures==3.2.0 requests==2.21.0 flaky==3.4.0 -attrs==19.1.0 +attrs==19.1.0 psutil==5.7.2 -gevent==1.1b5 \ No newline at end of file +gevent==1.1b5 +grequests==0.6.0 \ No newline at end of file From a1e62fa810c5e6da9e30b357ef13d06e9f8f9136 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 14:31:55 +0800 Subject: [PATCH 12/46] new file: t/pycases/cases/nginx.conf modified: t/pycases/cases/test_base.py --- t/pycases/cases/nginx.conf | 16 ++++++++++++++++ t/pycases/cases/test_base.py | 11 +---------- 2 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 t/pycases/cases/nginx.conf diff --git a/t/pycases/cases/nginx.conf b/t/pycases/cases/nginx.conf new file mode 100644 index 000000000000..7c068984dddb --- /dev/null +++ b/t/pycases/cases/nginx.conf @@ -0,0 +1,16 @@ +worker_processes 1; +error_log error.log; +events { + worker_connections 1024; +} +http { + server { + listen 9000; + location / { + default_type text/html; + content_by_lua ' + ngx.say("

Hello, World!

") + '; + } + } +} diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 8b3e8f79fa34..c01b75d034b1 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -34,16 +34,6 @@ def setup_module(): def teardown_module(): killprocesstree(nginx_pid) -# 单机最少 2 core,用例前后检查点: -# 1. Nginx 里面是否有 error.log 。 -# 2. 运行场景前后进程资源状态值:进程 ID,进程内存。 -# 3. 场景的运行,都应该是对单个 APISIX 服务做测试。 -# ## 场景 1, route -# 1. 添加 /hello 路由,并把它转发到上游 9000 这个端口上,产生 200 应答。 -# 2. 发多个请求(5-10s)-> 200 response。 -# 3. 删除操作 /hello 路由。 -# 4. 发多个请求 (5-10s) -> 404 response。 - def test_01(): cfgdata = { "uri": "/hello", @@ -60,6 +50,7 @@ def test_01(): r = requests.get("%s/hello"%apisixhost) assert r.status_code == 200 and "Hello, World!" in r.content r = geturl("%s/hello"%apisixhost,10) + print(len(r)) assert all(i == 200 for i in r) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) From c6d4f79ac3943e9803fdc8770522a6a9eeac34f8 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 14:58:33 +0800 Subject: [PATCH 13/46] modified: t/pycases/cases/nginx.conf --- t/pycases/cases/nginx.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/pycases/cases/nginx.conf b/t/pycases/cases/nginx.conf index 7c068984dddb..1a26a3ce9910 100644 --- a/t/pycases/cases/nginx.conf +++ b/t/pycases/cases/nginx.conf @@ -1,14 +1,14 @@ worker_processes 1; error_log error.log; events { - worker_connections 1024; + worker_connections 4096; } http { server { listen 9000; location / { default_type text/html; - content_by_lua ' + content_by_lua_block ' ngx.say("

Hello, World!

") '; } From e643c4647547e4f1adbf7d6f87e3b4276349fced Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 15:24:28 +0800 Subject: [PATCH 14/46] modified: t/pycases/cases/test_base.py --- t/pycases/cases/test_base.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index c01b75d034b1..76beb38e55d7 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -25,37 +25,41 @@ def setup_module(): global headers,nginx_pid,apisixhost apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} - casepath = cur_file_dir() - confpath = casepath + "/nginx.conf" - p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) - p.wait() - nginx_pid = p.pid+1 + # casepath = cur_file_dir() + # confpath = casepath + "/nginx.conf" + # p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + # p.wait() + # nginx_pid = p.pid+1 def teardown_module(): - killprocesstree(nginx_pid) + pass + #killprocesstree(nginx_pid) def test_01(): cfgdata = { - "uri": "/hello", + "uri": "/apisix/status", "upstream": { "type": "roundrobin", "nodes": { - "127.0.0.1:9000": 1 + "39.97.63.215:80": 1 } } } r = requests.put("%s/apisix/admin/routes/1"%apisixhost, json=cfgdata,headers=headers ) r = json.loads(r.content) assert r["action"] == "set" - r = requests.get("%s/hello"%apisixhost) - assert r.status_code == 200 and "Hello, World!" in r.content - r = geturl("%s/hello"%apisixhost,10) + r = requests.get("%s/apisix/status"%apisixhost) + assert r.status_code == 200 + r = geturl("%s/apisix/status"%apisixhost,1) print(len(r)) assert all(i == 200 for i in r) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) r = requests.get("%s/hello"%apisixhost) assert r.status_code == 404 - r = geturl("%s/hello"%apisixhost,10) + r = geturl("%s/hello"%apisixhost,1) assert all(i == 404 for i in r) +setup_module() +test_01() +teardown_module() From 5be7b6381d3d5df030b1db631d123f12caee4d76 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 15:43:12 +0800 Subject: [PATCH 15/46] modified: t/pycases/cases/test_base.py --- t/pycases/cases/test_base.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 76beb38e55d7..39ba08d1fa40 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -33,33 +33,30 @@ def setup_module(): def teardown_module(): pass - #killprocesstree(nginx_pid) + # killprocesstree(nginx_pid) def test_01(): cfgdata = { - "uri": "/apisix/status", + "uri": "/hello", "upstream": { "type": "roundrobin", "nodes": { - "39.97.63.215:80": 1 + "127.0.0.1:9000": 1 } } } r = requests.put("%s/apisix/admin/routes/1"%apisixhost, json=cfgdata,headers=headers ) r = json.loads(r.content) assert r["action"] == "set" - r = requests.get("%s/apisix/status"%apisixhost) - assert r.status_code == 200 - r = geturl("%s/apisix/status"%apisixhost,1) + r = requests.get("%s/hello"%apisixhost) + assert r.status_code == 200 and "Hello, World!" in r.content + r = geturl("%s/hello"%apisixhost,10) print(len(r)) assert all(i == 200 for i in r) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) r = requests.get("%s/hello"%apisixhost) assert r.status_code == 404 - r = geturl("%s/hello"%apisixhost,1) + r = geturl("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) -setup_module() -test_01() -teardown_module() From 27975c18ceb53824ebc6d04deeecddeb39912f5d Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 15:47:18 +0800 Subject: [PATCH 16/46] modified: .travis/linux_apisix_integrationtest_runner.sh --- .travis/linux_apisix_integrationtest_runner.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index 618cce459272..d22a15ababa0 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -144,6 +144,9 @@ script() { cd t/pycases/ sudo python runtest.py + #start another nginx for test + sudo openresty -p "cases" -c "cases/nginx.conf" + #run test pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } From 7da23518513d867423aba6de678629e8c4e973e0 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 15:56:38 +0800 Subject: [PATCH 17/46] modified: .travis/linux_apisix_integrationtest_runner.sh --- .travis/linux_apisix_integrationtest_runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index d22a15ababa0..d38143fe1773 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -145,7 +145,7 @@ script() { cd t/pycases/ sudo python runtest.py #start another nginx for test - sudo openresty -p "cases" -c "cases/nginx.conf" + openresty -p "cases" -c "cases/nginx.conf" #run test pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" From 260d13e5e556822efb3001c8bae3809efbc88681 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 16:04:09 +0800 Subject: [PATCH 18/46] modified: .travis/linux_apisix_integrationtest_runner.sh modified: t/pycases/cases/test_base.py --- .travis/linux_apisix_integrationtest_runner.sh | 4 ++-- t/pycases/cases/test_base.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index d38143fe1773..fdd1a3e98a16 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -145,9 +145,9 @@ script() { cd t/pycases/ sudo python runtest.py #start another nginx for test - openresty -p "cases" -c "cases/nginx.conf" + #openresty -p "cases" -c "cases/nginx.conf" #run test - pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" + sudo pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 39ba08d1fa40..ed4b116dd308 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -25,15 +25,15 @@ def setup_module(): global headers,nginx_pid,apisixhost apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} - # casepath = cur_file_dir() - # confpath = casepath + "/nginx.conf" - # p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) - # p.wait() - # nginx_pid = p.pid+1 + casepath = cur_file_dir() + confpath = casepath + "/nginx.conf" + p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + p.wait() + nginx_pid = p.pid+1 def teardown_module(): pass - # killprocesstree(nginx_pid) + killprocesstree(nginx_pid) def test_01(): cfgdata = { From 3940df149de4ccaaf9e8b6ea9b9ceaf6795358a5 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 16:10:35 +0800 Subject: [PATCH 19/46] modified: .travis/linux_apisix_integrationtest_runner.sh modified: t/pycases/cases/test_base.py --- .travis/linux_apisix_integrationtest_runner.sh | 4 ++-- t/pycases/cases/test_base.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index fdd1a3e98a16..03adc389d166 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -145,9 +145,9 @@ script() { cd t/pycases/ sudo python runtest.py #start another nginx for test - #openresty -p "cases" -c "cases/nginx.conf" + openresty -p "./cases" -c "./cases/nginx.conf" #run test - sudo pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" + pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index ed4b116dd308..39ba08d1fa40 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -25,15 +25,15 @@ def setup_module(): global headers,nginx_pid,apisixhost apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} - casepath = cur_file_dir() - confpath = casepath + "/nginx.conf" - p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) - p.wait() - nginx_pid = p.pid+1 + # casepath = cur_file_dir() + # confpath = casepath + "/nginx.conf" + # p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + # p.wait() + # nginx_pid = p.pid+1 def teardown_module(): pass - killprocesstree(nginx_pid) + # killprocesstree(nginx_pid) def test_01(): cfgdata = { From c3494dd1eca066431f92a87e600732a210d05ac4 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 16:17:10 +0800 Subject: [PATCH 20/46] modified: ../.travis/linux_apisix_integrationtest_runner.sh modified: pycases/cases/nginx.conf --- .travis/linux_apisix_integrationtest_runner.sh | 2 +- t/pycases/cases/nginx.conf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index 03adc389d166..a462aca04f44 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -145,7 +145,7 @@ script() { cd t/pycases/ sudo python runtest.py #start another nginx for test - openresty -p "./cases" -c "./cases/nginx.conf" + openresty -p "./cases" -c "nginx.conf" #run test pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" diff --git a/t/pycases/cases/nginx.conf b/t/pycases/cases/nginx.conf index 1a26a3ce9910..4bf794e55538 100644 --- a/t/pycases/cases/nginx.conf +++ b/t/pycases/cases/nginx.conf @@ -8,9 +8,9 @@ http { listen 9000; location / { default_type text/html; - content_by_lua_block ' + content_by_lua_block { ngx.say("

Hello, World!

") - '; + } } } } From a5794f09fb1c751dfe4624d0022924dca1d48fbe Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 16:37:25 +0800 Subject: [PATCH 21/46] modified: .travis/linux_apisix_integrationtest_runner.sh --- .travis/linux_apisix_integrationtest_runner.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index a462aca04f44..8445f2d770d2 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -145,7 +145,9 @@ script() { cd t/pycases/ sudo python runtest.py #start another nginx for test - openresty -p "./cases" -c "nginx.conf" + casepath=$(pwd)"/case" + caseconfpath=$casepath"/nginx.conf" + openresty -p $casepath -c $caseconfpath #run test pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" From e77edd4b87847dba315e24a19a54cf85253eb979 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 16:46:31 +0800 Subject: [PATCH 22/46] modified: ../.travis/linux_apisix_integrationtest_runner.sh modified: pycases/cases/nginx.conf --- .travis/linux_apisix_integrationtest_runner.sh | 1 + t/pycases/cases/nginx.conf | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index 8445f2d770d2..feba0e167a63 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -145,6 +145,7 @@ script() { cd t/pycases/ sudo python runtest.py #start another nginx for test + mkdir -p cases/logs casepath=$(pwd)"/case" caseconfpath=$casepath"/nginx.conf" openresty -p $casepath -c $caseconfpath diff --git a/t/pycases/cases/nginx.conf b/t/pycases/cases/nginx.conf index 4bf794e55538..5f51d87a2a25 100644 --- a/t/pycases/cases/nginx.conf +++ b/t/pycases/cases/nginx.conf @@ -1,5 +1,5 @@ worker_processes 1; -error_log error.log; +error_log logs/error.log; events { worker_connections 4096; } From 17ef3da71e73d3ca224dd4d2368a976293d5cac3 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 16:52:57 +0800 Subject: [PATCH 23/46] modified: ../.travis/linux_apisix_integrationtest_runner.sh --- .travis/linux_apisix_integrationtest_runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index feba0e167a63..c70b12ffdef1 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -146,7 +146,7 @@ script() { sudo python runtest.py #start another nginx for test mkdir -p cases/logs - casepath=$(pwd)"/case" + casepath=$(pwd)"/cases" caseconfpath=$casepath"/nginx.conf" openresty -p $casepath -c $caseconfpath #run test From a03d36199b504666e0bd2f823251bc86bc51a7b6 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 17:06:21 +0800 Subject: [PATCH 24/46] test start nginx in py --- .travis/linux_apisix_integrationtest_runner.sh | 6 +++--- t/pycases/cases/test_base.py | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index c70b12ffdef1..47e39604188c 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -146,9 +146,9 @@ script() { sudo python runtest.py #start another nginx for test mkdir -p cases/logs - casepath=$(pwd)"/cases" - caseconfpath=$casepath"/nginx.conf" - openresty -p $casepath -c $caseconfpath + # casepath=$(pwd)"/cases" + # caseconfpath=$casepath"/nginx.conf" + # openresty -p $casepath -c $caseconfpath #run test pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 39ba08d1fa40..56f5773645b9 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -25,11 +25,11 @@ def setup_module(): global headers,nginx_pid,apisixhost apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} - # casepath = cur_file_dir() - # confpath = casepath + "/nginx.conf" - # p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) - # p.wait() - # nginx_pid = p.pid+1 + casepath = cur_file_dir() + confpath = casepath + "/nginx.conf" + p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + p.wait() + nginx_pid = p.pid+1 def teardown_module(): pass @@ -51,7 +51,6 @@ def test_01(): r = requests.get("%s/hello"%apisixhost) assert r.status_code == 200 and "Hello, World!" in r.content r = geturl("%s/hello"%apisixhost,10) - print(len(r)) assert all(i == 200 for i in r) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) From 5dab34199bdfd0653b76f0f4bd394ea71293b93a Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 18:27:31 +0800 Subject: [PATCH 25/46] add res moniter --- .../linux_apisix_integrationtest_runner.sh | 5 ----- t/pycases/cases/test_base.py | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index 47e39604188c..04c6b175f1ed 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -144,12 +144,7 @@ script() { cd t/pycases/ sudo python runtest.py - #start another nginx for test mkdir -p cases/logs - # casepath=$(pwd)"/cases" - # caseconfpath=$casepath"/nginx.conf" - # openresty -p $casepath -c $caseconfpath - #run test pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 56f5773645b9..275f05ff6d7b 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -8,6 +8,19 @@ def killprocesstree(id): psutil.Process(int(pid)).terminate() psutil.Process(id).terminate() +def getpidbyname(): + name = "apisix" + cmd = "ps -ef | grep %s | grep nginx | grep -v grep | grep -v %s/t | awk '{print $2}'"%(name,name) + p = subprocess.Popen(cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) + p.wait() + return p.stdout.read() + +def getchildres(pid): + for cpid in psutil.pids(): + if psutil.Process(int(cpid)).ppid()==int(pid): + p = psutil.Process(int(cpid)) + print(cpid,p.memory_percent()) + def cur_file_dir(): return os.path.split(os.path.realpath(__file__))[0] @@ -33,9 +46,10 @@ def setup_module(): def teardown_module(): pass - # killprocesstree(nginx_pid) + #killprocesstree(nginx_pid) def test_01(): + getchildres(getpidbyname()) cfgdata = { "uri": "/hello", "upstream": { @@ -52,10 +66,11 @@ def test_01(): assert r.status_code == 200 and "Hello, World!" in r.content r = geturl("%s/hello"%apisixhost,10) assert all(i == 200 for i in r) + getchildres(getpidbyname()) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) r = requests.get("%s/hello"%apisixhost) assert r.status_code == 404 r = geturl("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) - + getchildres(getpidbyname()) From d9ed8c8483aa4777780528a0cc64ca55588fe8fd Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 18:41:39 +0800 Subject: [PATCH 26/46] add error log moniter --- t/pycases/cases/test_base.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 275f05ff6d7b..218efd35c460 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -35,7 +35,8 @@ def geturl(url,times): return r def setup_module(): - global headers,nginx_pid,apisixhost + global headers,nginx_pid,apisixhost,apisixpid + apisixpid = getpidbyname() apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} casepath = cur_file_dir() @@ -49,7 +50,7 @@ def teardown_module(): #killprocesstree(nginx_pid) def test_01(): - getchildres(getpidbyname()) + getchildres(apisixpid) cfgdata = { "uri": "/hello", "upstream": { @@ -66,11 +67,15 @@ def test_01(): assert r.status_code == 200 and "Hello, World!" in r.content r = geturl("%s/hello"%apisixhost,10) assert all(i == 200 for i in r) - getchildres(getpidbyname()) + getchildres(apisixpid) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) r = requests.get("%s/hello"%apisixhost) assert r.status_code == 404 r = geturl("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) - getchildres(getpidbyname()) + getchildres(apisixpid) + + print("the error log:\n") + with open(cur_file_dir()+r"/logs/error.log") as fh: + print(fh.read()) From 5f2e2abfba19f8d34fa675cd72cbf731b37c2589 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 18:49:17 +0800 Subject: [PATCH 27/46] modify test port --- t/pycases/cases/nginx.conf | 2 +- t/pycases/cases/test_base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/pycases/cases/nginx.conf b/t/pycases/cases/nginx.conf index 5f51d87a2a25..01cf460bdd55 100644 --- a/t/pycases/cases/nginx.conf +++ b/t/pycases/cases/nginx.conf @@ -5,7 +5,7 @@ events { } http { server { - listen 9000; + listen 9666; location / { default_type text/html; content_by_lua_block { diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 218efd35c460..86bc5981fec4 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -56,7 +56,7 @@ def test_01(): "upstream": { "type": "roundrobin", "nodes": { - "127.0.0.1:9000": 1 + "127.0.0.1:9666": 1 } } } From 8949e229801a034244ff0a4867b2dd5a2c1a03d9 Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 18:59:28 +0800 Subject: [PATCH 28/46] modify moniter --- t/pycases/cases/test_base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 86bc5981fec4..14e3f236c727 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -35,8 +35,9 @@ def geturl(url,times): return r def setup_module(): - global headers,nginx_pid,apisixhost,apisixpid + global headers,nginx_pid,apisixhost,apisixpid,apisixpath apisixpid = getpidbyname() + apisixpath = psutil.Process(apisixpid).cwd() apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} casepath = cur_file_dir() @@ -77,5 +78,6 @@ def test_01(): getchildres(apisixpid) print("the error log:\n") - with open(cur_file_dir()+r"/logs/error.log") as fh: + + with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) From b2e1fbcf3a89ae01f9b87cb9c576b74be9d34bff Mon Sep 17 00:00:00 2001 From: idbeta Date: Wed, 23 Sep 2020 19:05:57 +0800 Subject: [PATCH 29/46] fix bug --- t/pycases/cases/test_base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/t/pycases/cases/test_base.py b/t/pycases/cases/test_base.py index 14e3f236c727..5092285823eb 100644 --- a/t/pycases/cases/test_base.py +++ b/t/pycases/cases/test_base.py @@ -36,7 +36,7 @@ def geturl(url,times): def setup_module(): global headers,nginx_pid,apisixhost,apisixpid,apisixpath - apisixpid = getpidbyname() + apisixpid = int(getpidbyname()) apisixpath = psutil.Process(apisixpid).cwd() apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} @@ -78,6 +78,5 @@ def test_01(): getchildres(apisixpid) print("the error log:\n") - with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) From 19e3bf431246412e5344a500da76c99d92706d07 Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 11:19:50 +0800 Subject: [PATCH 30/46] rename casedir's name --- .../linux_apisix_integrationtest_runner.sh | 4 ++-- .../cases/nginx.conf | 0 .../cases/test_base.py | 19 ++++++++++++------- .../requirements.txt | 0 t/{pycases => integrationtest}/runtest.py | 0 5 files changed, 14 insertions(+), 9 deletions(-) rename t/{pycases => integrationtest}/cases/nginx.conf (100%) rename t/{pycases => integrationtest}/cases/test_base.py (82%) rename t/{pycases => integrationtest}/requirements.txt (100%) rename t/{pycases => integrationtest}/runtest.py (100%) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index 04c6b175f1ed..08dc8069a244 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -142,9 +142,9 @@ script() { exit 1 fi - cd t/pycases/ + cd t/integrationtest/ sudo python runtest.py - mkdir -p cases/logs + # mkdir -p cases/logs pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/pycases/cases/nginx.conf b/t/integrationtest/cases/nginx.conf similarity index 100% rename from t/pycases/cases/nginx.conf rename to t/integrationtest/cases/nginx.conf diff --git a/t/pycases/cases/test_base.py b/t/integrationtest/cases/test_base.py similarity index 82% rename from t/pycases/cases/test_base.py rename to t/integrationtest/cases/test_base.py index 5092285823eb..b6c2e262ce0b 100644 --- a/t/pycases/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -13,13 +13,13 @@ def getpidbyname(): cmd = "ps -ef | grep %s | grep nginx | grep -v grep | grep -v %s/t | awk '{print $2}'"%(name,name) p = subprocess.Popen(cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) p.wait() - return p.stdout.read() + return p.stdout.read().strip() -def getchildres(pid): +def getworkerres(pid): for cpid in psutil.pids(): if psutil.Process(int(cpid)).ppid()==int(pid): p = psutil.Process(int(cpid)) - print(cpid,p.memory_percent()) + print(cpid,p.cpu_percent(interval=1.0),p.memory_percent()) def cur_file_dir(): return os.path.split(os.path.realpath(__file__))[0] @@ -41,7 +41,9 @@ def setup_module(): apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} casepath = cur_file_dir() + print("caspath:",casepath) confpath = casepath + "/nginx.conf" + os.makedirs(casepath+"/logs") p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 @@ -51,7 +53,8 @@ def teardown_module(): #killprocesstree(nginx_pid) def test_01(): - getchildres(apisixpid) + print("APISIX's resource occupation(before test):\n") + getworkerres(apisixpid) cfgdata = { "uri": "/hello", "upstream": { @@ -68,15 +71,17 @@ def test_01(): assert r.status_code == 200 and "Hello, World!" in r.content r = geturl("%s/hello"%apisixhost,10) assert all(i == 200 for i in r) - getchildres(apisixpid) + print("APISIX's resource occupation(after set route and request test):\n") + getworkerres(apisixpid) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) r = requests.get("%s/hello"%apisixhost) assert r.status_code == 404 r = geturl("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) - getchildres(apisixpid) + print("APISIX's resource occupation(after delete route and request test):\n") + getworkerres(apisixpid) - print("the error log:\n") + print("APISIX's error log:\n") with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) diff --git a/t/pycases/requirements.txt b/t/integrationtest/requirements.txt similarity index 100% rename from t/pycases/requirements.txt rename to t/integrationtest/requirements.txt diff --git a/t/pycases/runtest.py b/t/integrationtest/runtest.py similarity index 100% rename from t/pycases/runtest.py rename to t/integrationtest/runtest.py From 7b3c22e7f98e76db98ad505f94ef469a6a1b1565 Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 11:34:59 +0800 Subject: [PATCH 31/46] fix mkdir --- t/integrationtest/cases/test_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index b6c2e262ce0b..ca9897102d9a 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -43,7 +43,7 @@ def setup_module(): casepath = cur_file_dir() print("caspath:",casepath) confpath = casepath + "/nginx.conf" - os.makedirs(casepath+"/logs") + os.mkdir("logs") p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 @@ -53,7 +53,7 @@ def teardown_module(): #killprocesstree(nginx_pid) def test_01(): - print("APISIX's resource occupation(before test):\n") + print("APISIX's resource occupation(before test):") getworkerres(apisixpid) cfgdata = { "uri": "/hello", @@ -79,9 +79,9 @@ def test_01(): assert r.status_code == 404 r = geturl("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) - print("APISIX's resource occupation(after delete route and request test):\n") + print("APISIX's resource occupation(after delete route and request test):") getworkerres(apisixpid) - print("APISIX's error log:\n") + print("APISIX's error log:") with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) From 6e447d3e2c0ae2c2289c1e7157696f24f103a4dd Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 11:49:03 +0800 Subject: [PATCH 32/46] add try except --- .travis/linux_apisix_integrationtest_runner.sh | 2 +- t/integrationtest/cases/test_base.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index 08dc8069a244..ecfdebdc67da 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -144,7 +144,7 @@ script() { cd t/integrationtest/ sudo python runtest.py - # mkdir -p cases/logs + python --version pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index ca9897102d9a..c26ed11c588a 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -43,7 +43,10 @@ def setup_module(): casepath = cur_file_dir() print("caspath:",casepath) confpath = casepath + "/nginx.conf" - os.mkdir("logs") + try: + os.mkdir("logs") + except Exception as e: + pass p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 From 99d907089789e8ed9a09b2a3f2b45c890744a266 Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 11:58:36 +0800 Subject: [PATCH 33/46] remove mkdir --- .travis/linux_apisix_integrationtest_runner.sh | 2 +- t/integrationtest/cases/test_base.py | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index ecfdebdc67da..fb088a735f41 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -144,7 +144,7 @@ script() { cd t/integrationtest/ sudo python runtest.py - python --version + mkdir -p cases/logs pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index c26ed11c588a..67bd666653f7 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -41,12 +41,7 @@ def setup_module(): apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} casepath = cur_file_dir() - print("caspath:",casepath) confpath = casepath + "/nginx.conf" - try: - os.mkdir("logs") - except Exception as e: - pass p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 From 03b6ae0a7b78a49c664aa8bc0aaf595a0319424c Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 12:12:12 +0800 Subject: [PATCH 34/46] test listdir --- t/integrationtest/cases/test_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 67bd666653f7..113f200efa89 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -45,6 +45,7 @@ def setup_module(): p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 + print(os.listdir("./")) def teardown_module(): pass @@ -69,7 +70,7 @@ def test_01(): assert r.status_code == 200 and "Hello, World!" in r.content r = geturl("%s/hello"%apisixhost,10) assert all(i == 200 for i in r) - print("APISIX's resource occupation(after set route and request test):\n") + print("APISIX's resource occupation(after set route and request test):") getworkerres(apisixpid) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) From 0d107c6bb7a346741b7ae1eb38e18caa69052a9e Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 12:22:14 +0800 Subject: [PATCH 35/46] add judge whether error log exists --- t/integrationtest/cases/test_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 113f200efa89..6c2ed818eaec 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -45,7 +45,7 @@ def setup_module(): p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 - print(os.listdir("./")) + print(os.listdir("./cases")) def teardown_module(): pass @@ -82,5 +82,6 @@ def test_01(): getworkerres(apisixpid) print("APISIX's error log:") + print(os.path.exists(apisixpath+r"/logs/error.log")) with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) From ed35dca63d9e200189067c38fb8f28d45a7a8f01 Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 12:30:32 +0800 Subject: [PATCH 36/46] give a try to add logs... --- .travis/linux_apisix_integrationtest_runner.sh | 2 +- t/integrationtest/cases/test_base.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index fb088a735f41..25496ae56acb 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -144,7 +144,7 @@ script() { cd t/integrationtest/ sudo python runtest.py - mkdir -p cases/logs + #mkdir -p cases/logs pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 6c2ed818eaec..e27c66aa4d12 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -42,10 +42,13 @@ def setup_module(): headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} casepath = cur_file_dir() confpath = casepath + "/nginx.conf" + try: + os.makedirs("./cases/logs") + except Exception as e: + pass p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 - print(os.listdir("./cases")) def teardown_module(): pass @@ -82,6 +85,5 @@ def test_01(): getworkerres(apisixpid) print("APISIX's error log:") - print(os.path.exists(apisixpath+r"/logs/error.log")) with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) From 0bf4c56fe14ae699eb4577d12b5800c32139018d Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 12:43:51 +0800 Subject: [PATCH 37/46] add orgin jobs --- .github/workflows/build.yml | 2 +- .travis/linux_apisix_integrationtest_runner.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf17d3b5c7f5..729227a5b6b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: platform: [ubuntu-18.04] - os_name: [linux_apisix_integrationtest] + os_name: [linux_openresty, linux_tengine, linux_apisix_master_luarocks, linux_apisix_current_luarocks, linux_openresty_mtls, linux_apisix_integrationtest] include: - platform: macos-latest os_name: osx_openresty diff --git a/.travis/linux_apisix_integrationtest_runner.sh b/.travis/linux_apisix_integrationtest_runner.sh index 25496ae56acb..83f5a2d51847 100755 --- a/.travis/linux_apisix_integrationtest_runner.sh +++ b/.travis/linux_apisix_integrationtest_runner.sh @@ -144,7 +144,6 @@ script() { cd t/integrationtest/ sudo python runtest.py - #mkdir -p cases/logs pytest --force-flaky --max-runs=3 --no-flaky-report -v -s "cases" } From aaff4708ae2a980681e7c7ec608926ba39ba90eb Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 12:48:42 +0800 Subject: [PATCH 38/46] modify func name --- t/integrationtest/cases/test_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index e27c66aa4d12..6335a8c4951a 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -24,7 +24,7 @@ def getworkerres(pid): def cur_file_dir(): return os.path.split(os.path.realpath(__file__))[0] -def geturl(url,times): +def requesttest(url,times): start = time.time() tasks = [] r = [] @@ -71,7 +71,7 @@ def test_01(): assert r["action"] == "set" r = requests.get("%s/hello"%apisixhost) assert r.status_code == 200 and "Hello, World!" in r.content - r = geturl("%s/hello"%apisixhost,10) + r = requesttest("%s/hello"%apisixhost,10) assert all(i == 200 for i in r) print("APISIX's resource occupation(after set route and request test):") getworkerres(apisixpid) @@ -79,7 +79,7 @@ def test_01(): r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) r = requests.get("%s/hello"%apisixhost) assert r.status_code == 404 - r = geturl("%s/hello"%apisixhost,10) + r = requesttest("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) print("APISIX's resource occupation(after delete route and request test):") getworkerres(apisixpid) From 8da18fbb5b97626e02204e5bbfa482f323bd3284 Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 13:08:03 +0800 Subject: [PATCH 39/46] fix issues found in other tests --- t/integrationtest/cases/nginx.conf | 18 +++++++++++++++++- t/integrationtest/cases/test_base.py | 28 ++++++++++++++++++++++------ t/integrationtest/runtest.py | 20 ++++++++++++++++++-- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/t/integrationtest/cases/nginx.conf b/t/integrationtest/cases/nginx.conf index 01cf460bdd55..e9b9aedb6a14 100644 --- a/t/integrationtest/cases/nginx.conf +++ b/t/integrationtest/cases/nginx.conf @@ -1,3 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + worker_processes 1; error_log logs/error.log; events { @@ -13,4 +29,4 @@ http { } } } -} +} \ No newline at end of file diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 6335a8c4951a..e16967f66035 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -1,17 +1,33 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + #!/usr/bin/env python #-*- coding: utf-8 -*- import sys,os,time,requests,json,subprocess,signal,psutil,grequests def killprocesstree(id): for pid in psutil.pids(): - if psutil.Process(int(pid)).ppid()==id: - psutil.Process(int(pid)).terminate() + if psutil.Process(int(pid)).ppid()==id: + psutil.Process(int(pid)).terminate() psutil.Process(id).terminate() def getpidbyname(): name = "apisix" cmd = "ps -ef | grep %s | grep nginx | grep -v grep | grep -v %s/t | awk '{print $2}'"%(name,name) - p = subprocess.Popen(cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) + p = subprocess.Popen(cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) p.wait() return p.stdout.read().strip() @@ -20,7 +36,7 @@ def getworkerres(pid): if psutil.Process(int(cpid)).ppid()==int(pid): p = psutil.Process(int(cpid)) print(cpid,p.cpu_percent(interval=1.0),p.memory_percent()) - + def cur_file_dir(): return os.path.split(os.path.realpath(__file__))[0] @@ -46,7 +62,7 @@ def setup_module(): os.makedirs("./cases/logs") except Exception as e: pass - p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() nginx_pid = p.pid+1 @@ -86,4 +102,4 @@ def test_01(): print("APISIX's error log:") with open(apisixpath+r"/logs/error.log") as fh: - print(fh.read()) + print(fh.read()) \ No newline at end of file diff --git a/t/integrationtest/runtest.py b/t/integrationtest/runtest.py index c20b253fe114..160408495bcb 100644 --- a/t/integrationtest/runtest.py +++ b/t/integrationtest/runtest.py @@ -1,3 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + #!/usr/bin/env python #-*- coding: utf-8 -*- @@ -14,7 +30,7 @@ def cur_file_dir(): def runcase(casedirpath): updatepip = "curl https://bootstrap.pypa.io/get-pip.py | python" requirements = "pip install -r %s/requirements.txt"%cur_file_dir() - + r_exc_case_cmd = subprocess.Popen(updatepip, stderr=subprocess.PIPE,shell=True) r_exc_case_cmd.wait() err = r_exc_case_cmd.stderr.read() @@ -34,4 +50,4 @@ def runcase(casedirpath): #shutil.rmtree(casedirpath+r'/__pycache__') casepath = cur_file_dir()+"/cases" -runcase(casepath) \ No newline at end of file +runcase(casepath) From 742c179309a23c643341b9249f40af347a82a0dd Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 13:17:56 +0800 Subject: [PATCH 40/46] add licenses --- t/integrationtest/cases/nginx.conf | 3 ++- t/integrationtest/cases/test_base.py | 3 ++- t/integrationtest/runtest.py | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/t/integrationtest/cases/nginx.conf b/t/integrationtest/cases/nginx.conf index e9b9aedb6a14..9e261092d50b 100644 --- a/t/integrationtest/cases/nginx.conf +++ b/t/integrationtest/cases/nginx.conf @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# worker_processes 1; error_log logs/error.log; @@ -29,4 +30,4 @@ http { } } } -} \ No newline at end of file +} diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index e16967f66035..8933894818af 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# #!/usr/bin/env python #-*- coding: utf-8 -*- @@ -102,4 +103,4 @@ def test_01(): print("APISIX's error log:") with open(apisixpath+r"/logs/error.log") as fh: - print(fh.read()) \ No newline at end of file + print(fh.read()) diff --git a/t/integrationtest/runtest.py b/t/integrationtest/runtest.py index 160408495bcb..689d72ca3c3d 100644 --- a/t/integrationtest/runtest.py +++ b/t/integrationtest/runtest.py @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# #!/usr/bin/env python #-*- coding: utf-8 -*- From 037974b6bafb289ecd9f40f37810805eadc88d17 Mon Sep 17 00:00:00 2001 From: idbeta Date: Thu, 24 Sep 2020 13:56:15 +0800 Subject: [PATCH 41/46] for ci test --- t/integrationtest/cases/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 8933894818af..5815887631b5 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -69,7 +69,7 @@ def setup_module(): def teardown_module(): pass - #killprocesstree(nginx_pid) + # killprocesstree(nginx_pid) def test_01(): print("APISIX's resource occupation(before test):") From 5cf4c02446aedc99bbf72bb1764331a2dff8bf9c Mon Sep 17 00:00:00 2001 From: idbeta Date: Mon, 28 Sep 2020 11:59:36 +0800 Subject: [PATCH 42/46] remove useless code --- t/integrationtest/cases/test_base.py | 56 ++++++++++++++++------------ 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 5815887631b5..7977ed804e5f 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -17,26 +17,29 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- -import sys,os,time,requests,json,subprocess,signal,psutil,grequests +import sys,os,time,json,subprocess,signal +import requests,psutil,grequests -def killprocesstree(id): - for pid in psutil.pids(): - if psutil.Process(int(pid)).ppid()==id: - psutil.Process(int(pid)).terminate() +def kill_processtree(id): + parent = psutil.Process(pid) + children = parent.children(recursive=True) + for p in children: + psutil.Process(p.pid).terminate() psutil.Process(id).terminate() -def getpidbyname(): +def get_pid_byname(): name = "apisix" cmd = "ps -ef | grep %s | grep nginx | grep -v grep | grep -v %s/t | awk '{print $2}'"%(name,name) p = subprocess.Popen(cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) p.wait() return p.stdout.read().strip() -def getworkerres(pid): - for cpid in psutil.pids(): - if psutil.Process(int(cpid)).ppid()==int(pid): - p = psutil.Process(int(cpid)) - print(cpid,p.cpu_percent(interval=1.0),p.memory_percent()) +def get_workerres(pid): + parent = psutil.Process(pid) + children = parent.children(recursive=True) + for p in children: + cp = psutil.Process(p.pid) + print(p.pid,cp.cpu_percent(interval=1.0),cp.memory_percent()) def cur_file_dir(): return os.path.split(os.path.realpath(__file__))[0] @@ -52,9 +55,17 @@ def requesttest(url,times): return r def setup_module(): - global headers,nginx_pid,apisixhost,apisixpid,apisixpath - apisixpid = int(getpidbyname()) + global headers,apisixhost,apisixpid,apisixpath + apisixpid = int(get_pid_byname()) apisixpath = psutil.Process(apisixpid).cwd() + print apisixpath + os.chdir(apisixpath) + subprocess.call("./bin/apisix stop",shell=True, stdout=subprocess.PIPE) + time.sleep(1) + subprocess.call("./bin/apisix start",shell=True, stdout=subprocess.PIPE) + time.sleep(1) + apisixpid = int(get_pid_byname()) + print("=============APISIX's pid:",apisixpid) apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} casepath = cur_file_dir() @@ -65,15 +76,14 @@ def setup_module(): pass p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() - nginx_pid = p.pid+1 def teardown_module(): pass - # killprocesstree(nginx_pid) -def test_01(): - print("APISIX's resource occupation(before test):") - getworkerres(apisixpid) +#verify the route after added and deleted routes +def test_basescenario01(): + print("=============APISIX's resource occupation(before test):") + get_workerres(apisixpid) cfgdata = { "uri": "/hello", "upstream": { @@ -90,17 +100,17 @@ def test_01(): assert r.status_code == 200 and "Hello, World!" in r.content r = requesttest("%s/hello"%apisixhost,10) assert all(i == 200 for i in r) - print("APISIX's resource occupation(after set route and request test):") - getworkerres(apisixpid) + print("=============APISIX's resource occupation(after set route and request test):") + get_workerres(apisixpid) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) r = requests.get("%s/hello"%apisixhost) assert r.status_code == 404 r = requesttest("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) - print("APISIX's resource occupation(after delete route and request test):") - getworkerres(apisixpid) + print("=============APISIX's resource occupation(after delete route and request test):") + get_workerres(apisixpid) - print("APISIX's error log:") + print("=============APISIX's error log:") with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) From 35facc7f238403e32b9de7231737b1bf92a3caaa Mon Sep 17 00:00:00 2001 From: idbeta Date: Mon, 28 Sep 2020 12:12:27 +0800 Subject: [PATCH 43/46] remove debug code --- t/integrationtest/cases/test_base.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 7977ed804e5f..7f05bd7d2987 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -58,7 +58,6 @@ def setup_module(): global headers,apisixhost,apisixpid,apisixpath apisixpid = int(get_pid_byname()) apisixpath = psutil.Process(apisixpid).cwd() - print apisixpath os.chdir(apisixpath) subprocess.call("./bin/apisix stop",shell=True, stdout=subprocess.PIPE) time.sleep(1) @@ -74,7 +73,8 @@ def setup_module(): os.makedirs("./cases/logs") except Exception as e: pass - p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], + stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() def teardown_module(): @@ -82,7 +82,7 @@ def teardown_module(): #verify the route after added and deleted routes def test_basescenario01(): - print("=============APISIX's resource occupation(before test):") + print("====APISIX's resource occupation(before test):") get_workerres(apisixpid) cfgdata = { "uri": "/hello", @@ -93,14 +93,14 @@ def test_basescenario01(): } } } - r = requests.put("%s/apisix/admin/routes/1"%apisixhost, json=cfgdata,headers=headers ) + r = requests.put("%s/apisix/admin/routes/1"%apisixhost, json=cfgdata,headers=headers) r = json.loads(r.content) assert r["action"] == "set" r = requests.get("%s/hello"%apisixhost) assert r.status_code == 200 and "Hello, World!" in r.content r = requesttest("%s/hello"%apisixhost,10) assert all(i == 200 for i in r) - print("=============APISIX's resource occupation(after set route and request test):") + print("====APISIX's resource occupation(after set route and request test):") get_workerres(apisixpid) r = requests.delete("%s/apisix/admin/routes/1"%apisixhost, headers=headers ) @@ -108,9 +108,9 @@ def test_basescenario01(): assert r.status_code == 404 r = requesttest("%s/hello"%apisixhost,10) assert all(i == 404 for i in r) - print("=============APISIX's resource occupation(after delete route and request test):") + print("====PISIX's resource occupation(after delete route and request test):") get_workerres(apisixpid) - print("=============APISIX's error log:") + print("====APISIX's error log:") with open(apisixpath+r"/logs/error.log") as fh: print(fh.read()) From 1ed1725fa6840f80b38bc12f180278a6c9b73b4d Mon Sep 17 00:00:00 2001 From: idbeta Date: Mon, 28 Sep 2020 12:19:36 +0800 Subject: [PATCH 44/46] fix bug --- t/integrationtest/cases/test_base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 7f05bd7d2987..e2f7b5536d16 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -73,8 +73,7 @@ def setup_module(): os.makedirs("./cases/logs") except Exception as e: pass - p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], - stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() def teardown_module(): From 037579b335784abe24e5323049737b58766844ae Mon Sep 17 00:00:00 2001 From: idbeta Date: Mon, 28 Sep 2020 14:19:15 +0800 Subject: [PATCH 45/46] update the test upstream's config file path --- t/integrationtest/cases/test_base.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index e2f7b5536d16..1e4c0e113460 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -67,13 +67,12 @@ def setup_module(): print("=============APISIX's pid:",apisixpid) apisixhost = "http://127.0.0.1:9080" headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"} - casepath = cur_file_dir() - confpath = casepath + "/nginx.conf" + confpath = "./t/integrationtest/cases/nginx.conf" try: - os.makedirs("./cases/logs") + os.makedirs("./t/integrationtest/cases/logs") except Exception as e: pass - p = subprocess.Popen(['openresty', '-p',casepath,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) + p = subprocess.Popen(['openresty', '-p', apisixpath ,'-c',confpath], stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = False) p.wait() def teardown_module(): From 145341f85b6b612228fa71dfcf48fd6aecb39e7d Mon Sep 17 00:00:00 2001 From: idbeta Date: Mon, 28 Sep 2020 14:39:41 +0800 Subject: [PATCH 46/46] fix bug:get apisix pid fail --- t/integrationtest/cases/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/integrationtest/cases/test_base.py b/t/integrationtest/cases/test_base.py index 1e4c0e113460..59ff2d2ccb7b 100644 --- a/t/integrationtest/cases/test_base.py +++ b/t/integrationtest/cases/test_base.py @@ -29,7 +29,7 @@ def kill_processtree(id): def get_pid_byname(): name = "apisix" - cmd = "ps -ef | grep %s | grep nginx | grep -v grep | grep -v %s/t | awk '{print $2}'"%(name,name) + cmd = "ps -ef | grep %s/conf | grep master | grep -v grep| awk '{print $2}'"%name p = subprocess.Popen(cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) p.wait() return p.stdout.read().strip()