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



##########
File path: t/specialtest/runtest.py
##########
@@ -0,0 +1,57 @@
+#
+# 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 random
+import subprocess
+import shutil
+import time
+import datetime
+import sys
+import os
+import json
+import re
+import base64
+from sys import version_info
+
+
+def cur_file_dir():
+    return os.path.split(os.path.realpath(__file__))[0]
+
+
+def env_prepare(casedirpath):
+    updatepip = "curl https://bootstrap.pypa.io/get-pip.py | python"
+    if version_info.major == 2:

Review comment:
       Why should it be compatible with python2.0?

##########
File path: t/specialtest/cases/test_fuzziing_uri_of_route.py
##########
@@ -0,0 +1,142 @@
+#
+# 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 os
+import time
+import subprocess
+import random
+import urllib
+import re
+import requests
+import psutil
+import grequests
+
+
+def get_pid_byname():
+    name = "apisix"
+    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()
+
+
+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]
+
+
+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, apisixhost, apisixpid, apisixpath
+    apisixpid = int(get_pid_byname())
+    apisixpath = psutil.Process(apisixpid).cwd()
+    os.chdir(apisixpath)
+
+    subprocess.call("./bin/apisix stop", shell=True, stdout=subprocess.PIPE)
+    time.sleep(1)
+
+    subprocess.Popen("> logs/error.log", shell=True, stdout=subprocess.PIPE)
+    subprocess.call("etcd &", shell=True, stdout=subprocess.PIPE)
+    time.sleep(5)
+
+    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"}
+    confpath = "./t/specialtest/cases/nginx.conf"
+    try:
+        os.makedirs("./t/specialtest/cases/logs")
+    except Exception as e:
+        pass
+    p = subprocess.Popen(['openresty', '-p', apisixpath, '-c', confpath],

Review comment:
       Isn't Apache APISIX already running? Why start another apisix?

##########
File path: t/specialtest/runtest.py
##########
@@ -0,0 +1,57 @@
+#
+# 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 random
+import subprocess
+import shutil
+import time
+import datetime
+import sys
+import os
+import json
+import re
+import base64
+from sys import version_info
+
+
+def cur_file_dir():
+    return os.path.split(os.path.realpath(__file__))[0]
+
+
+def env_prepare(casedirpath):
+    updatepip = "curl https://bootstrap.pypa.io/get-pip.py | python"
+    if version_info.major == 2:
+        requirements = "python -m pip install -r %s/requirements.txt" %\
+                     cur_file_dir()
+    else:
+        requirements = "python3 -m 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()
+
+    r_exc_case_cmd = subprocess.Popen(requirements, stderr=subprocess.PIPE,
+                                      shell=True)
+    r_exc_case_cmd.wait()
+    err = r_exc_case_cmd.stderr.read()
+
+casepath = cur_file_dir()+"/cases"
+env_prepare(casepath)

Review comment:
       Where to run the test case?

##########
File path: t/specialtest/cases/test_fuzziing_uri_of_route.py
##########
@@ -0,0 +1,142 @@
+#
+# 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 os
+import time
+import subprocess
+import random
+import urllib
+import re
+import requests
+import psutil
+import grequests
+
+
+def get_pid_byname():
+    name = "apisix"
+    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()
+
+
+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]
+
+
+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, apisixhost, apisixpid, apisixpath
+    apisixpid = int(get_pid_byname())
+    apisixpath = psutil.Process(apisixpid).cwd()
+    os.chdir(apisixpath)
+
+    subprocess.call("./bin/apisix stop", shell=True, stdout=subprocess.PIPE)
+    time.sleep(1)
+
+    subprocess.Popen("> logs/error.log", shell=True, stdout=subprocess.PIPE)
+    subprocess.call("etcd &", shell=True, stdout=subprocess.PIPE)
+    time.sleep(5)
+
+    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"}
+    confpath = "./t/specialtest/cases/nginx.conf"
+    try:
+        os.makedirs("./t/specialtest/cases/logs")
+    except Exception as e:
+        pass
+    p = subprocess.Popen(['openresty', '-p', apisixpath, '-c', confpath],
+                         stderr=subprocess.PIPE, stdout=subprocess.PIPE,
+                         shell=False)
+    p.wait()
+
+
+def teardown_module():
+    pass
+
+
+def test_fuzzing_uri_of_route():
+    print("====APISIX's resource occupation(before test):")
+    get_workerres(apisixpid)
+    # use environment variables "FUZZING_URI"
+    # you can setting the numbers of test uris
+    fuzzing_uri_nums = 1000 if not os.getenv('FUZZING_URI')\
+        else os.getenv('FUZZING_URI')
+    # not spupport * :
+    orgin_char = '''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+                 0123456789/-_~!();@&=+$,?#'.[]'''
+    for i in range(int(fuzzing_uri_nums)):
+        length = random.randint(1, 4080)
+        tmpuri = "".join(random.sample(list(orgin_char) *
+                         (length//len(orgin_char) + 1), length))
+        tmpuri = re.sub(r"/(\.+)/", "", tmpuri)
+        tmpuri = re.sub(r"/+", "/", tmpuri)
+        uri = "/hello%s" % tmpuri

Review comment:
       why use `hello` as prefix?




----------------------------------------------------------------
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:
[email protected]


Reply via email to