You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/09/27 08:41:32 UTC

[GitHub] [apisix] moonming commented on a change in pull request #2329: test:add a testcase to verify connections of etcd

moonming commented on a change in pull request #2329:
URL: https://github.com/apache/apisix/pull/2329#discussion_r495546079



##########
File path: .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_openresty, linux_tengine, linux_apisix_master_luarocks, linux_apisix_current_luarocks, linux_openresty_mtls, linux_apisix_integrationtest]

Review comment:
       `linux_apisix_integrationtest`  we can remove the `linux_apisix_` prefix.

##########
File path: .travis/linux_apisix_integrationtest_runner.sh
##########
@@ -0,0 +1,167 @@
+#!/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)

Review comment:
       should remove useless code.

##########
File path: t/integrationtest/cases/test_base.py
##########
@@ -0,0 +1,106 @@
+#
+# 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()
+    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().strip()
+
+def getworkerres(pid):

Review comment:
       ditto

##########
File path: t/integrationtest/cases/test_base.py
##########
@@ -0,0 +1,106 @@
+#
+# 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()
+    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().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 cur_file_dir():
+    return os.path.split(os.path.realpath(__file__))[0]
+
+def requesttest(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,nginx_pid,apisixhost,apisixpid,apisixpath
+    apisixpid = int(getpidbyname())
+    apisixpath = psutil.Process(apisixpid).cwd()
+    apisixhost = "http://127.0.0.1:9080"
+    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
+
+def teardown_module():
+    pass
+    # killprocesstree(nginx_pid)
+
+def test_basescenario01():

Review comment:
       bad name

##########
File path: t/integrationtest/cases/test_etcdlinks.py
##########
@@ -0,0 +1,63 @@
+#
+# 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,re
+
+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 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().strip()
+
+def getworkernum(pid):
+    num = 0
+    for cpid in psutil.pids():
+        if psutil.Process(int(cpid)).ppid()==int(pid):
+            num += 1
+    return num
+
+def getetcdlinks():
+    for r in psutil.process_iter():
+        if r.name()=="etcd":
+            return len(psutil.Process(r.pid).connections())
+
+def cur_file_dir():
+    return os.path.split(os.path.realpath(__file__))[0]
+
+def setup_module():
+    global headers,nginx_pid,apisixhost,apisixpid,apisixpath
+    apisixpid = int(getpidbyname())
+    apisixpath = psutil.Process(apisixpid).cwd()
+    apisixhost = "http://127.0.0.1:9080"
+    headers = {"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"}

Review comment:
       are those codes all useless?

##########
File path: .travis/linux_apisix_integrationtest_runner.sh
##########
@@ -0,0 +1,167 @@
+#!/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

Review comment:
       ditto.
   please check this cript one by one line, only keep what you need

##########
File path: t/integrationtest/cases/test_base.py
##########
@@ -0,0 +1,106 @@
+#
+# 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

Review comment:
       not following PEP8.
   please check python code style first.

##########
File path: t/integrationtest/cases/test_base.py
##########
@@ -0,0 +1,106 @@
+#
+# 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()
+    psutil.Process(id).terminate()
+
+def getpidbyname():

Review comment:
       get_pid_by_name

##########
File path: .travis/linux_apisix_integrationtest_runner.sh
##########
@@ -0,0 +1,167 @@
+#!/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)

Review comment:
       ditto

##########
File path: t/integrationtest/cases/test_base.py
##########
@@ -0,0 +1,106 @@
+#
+# 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()
+    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().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 cur_file_dir():
+    return os.path.split(os.path.realpath(__file__))[0]
+
+def requesttest(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,nginx_pid,apisixhost,apisixpid,apisixpath
+    apisixpid = int(getpidbyname())
+    apisixpath = psutil.Process(apisixpid).cwd()
+    apisixhost = "http://127.0.0.1:9080"
+    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
+
+def teardown_module():
+    pass
+    # killprocesstree(nginx_pid)
+
+def test_basescenario01():
+    print("APISIX's resource occupation(before test):")
+    getworkerres(apisixpid)
+    cfgdata = {

Review comment:
       what is `cfg`?

##########
File path: t/integrationtest/cases/test_base.py
##########
@@ -0,0 +1,106 @@
+#
+# 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()
+    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().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 cur_file_dir():
+    return os.path.split(os.path.realpath(__file__))[0]
+
+def requesttest(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,nginx_pid,apisixhost,apisixpid,apisixpath
+    apisixpid = int(getpidbyname())
+    apisixpath = psutil.Process(apisixpid).cwd()
+    apisixhost = "http://127.0.0.1:9080"
+    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

Review comment:
       you can not get nginx pid by this method.
   please get from `.pid` file.

##########
File path: t/integrationtest/cases/test_base.py
##########
@@ -0,0 +1,106 @@
+#

Review comment:
       Is this file related to PR?

##########
File path: .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_openresty, linux_tengine, linux_apisix_master_luarocks, linux_apisix_current_luarocks, linux_openresty_mtls, linux_apisix_integrationtest]

Review comment:
       how about `e2e_test`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org