You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/08/03 05:48:07 UTC

[apisix] branch master updated: test: check if the connection reuse works well (#7588)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 74c010b62 test: check if the connection reuse works well (#7588)
74c010b62 is described below

commit 74c010b62821d68e7026692c012ab690bcf90586
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Wed Aug 3 13:48:00 2022 +0800

    test: check if the connection reuse works well (#7588)
    
    It can detect the bug fixed in 7b6b30f4aa84e7d91e2a62280c27b5fab3fce46a
    
    Signed-off-by: spacewander <sp...@gmail.com>
---
 .github/workflows/fuzzing-ci.yaml | 12 +-----
 t/fuzzing/http_upstream.py        | 89 +++++++++++++++++++++++++++++++++++++++
 t/fuzzing/upstream/nginx.conf     | 17 ++++++++
 3 files changed, 108 insertions(+), 10 deletions(-)

diff --git a/.github/workflows/fuzzing-ci.yaml b/.github/workflows/fuzzing-ci.yaml
index 757bb93b7..60dc602c5 100644
--- a/.github/workflows/fuzzing-ci.yaml
+++ b/.github/workflows/fuzzing-ci.yaml
@@ -67,19 +67,11 @@ jobs:
         sudo apt remove python3-click
         pip install -r $PWD/t/fuzzing/requirements.txt
 
-    - name: run simpleroute test
+    - name: run tests
       run: |
         python $PWD/t/fuzzing/simpleroute_test.py
-
-    - name: run serverless route test
-      run: |
         python $PWD/t/fuzzing/serverless_route_test.py
-
-    - name: run vars route test
-      run: |
         python $PWD/t/fuzzing/vars_route_test.py
-
-    - name: run check leak test
-      run: |
         python $PWD/t/fuzzing/client_abort.py
         python $PWD/t/fuzzing/simple_http.py
+        python $PWD/t/fuzzing/http_upstream.py
diff --git a/t/fuzzing/http_upstream.py b/t/fuzzing/http_upstream.py
new file mode 100755
index 000000000..b3d0928df
--- /dev/null
+++ b/t/fuzzing/http_upstream.py
@@ -0,0 +1,89 @@
+#! /usr/bin/env python
+
+#
+# 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.
+#
+
+# This file provides a fuzzing test with different upstreams
+import http.client
+import json
+import random
+import threading
+from public import check_leak, run_test
+
+
+REQ_PER_THREAD = 50
+THREADS_NUM = 4
+TOTOL_ROUTES = 10
+
+
+def create_route():
+    for i in range(TOTOL_ROUTES):
+        conn = http.client.HTTPConnection("127.0.0.1", port=9080)
+        scheme = "http" if i % 2 == 0 else "https"
+        port = ":6666" if i % 2 == 0 else ":6667"
+        suffix = str(i + 1)
+        i = str(i)
+        conf = json.dumps({
+            "uri": "/*",
+            "host": "test" + i + ".com",
+            "plugins": {
+            },
+            "upstream": {
+                "scheme": scheme,
+                "nodes": {
+                    "127.0.0." + suffix + port: 1
+                },
+                "type": "roundrobin"
+            },
+        })
+
+        conn.request("PUT", "/apisix/admin/routes/" + i, conf,
+                headers={
+                    "X-API-KEY":"edd1c9f034335f136f87ad84b625c8f1",
+                })
+        response = conn.getresponse()
+        assert response.status <= 300, response.read()
+
+def req():
+    route_id = random.randrange(TOTOL_ROUTES)
+    conn = http.client.HTTPConnection("127.0.0.1", port=9080)
+    conn.request("GET", "/server_addr",
+            headers={
+                "Host":"test" + str(route_id) + ".com",
+            })
+    response = conn.getresponse()
+    assert response.status == 200, response.read()
+    ip = response.read().rstrip().decode()
+    suffix = str(route_id + 1)
+    assert "127.0.0." + suffix == ip, f"expect: 127.0.0.{suffix}, actual: {ip}"
+
+def run_in_thread():
+    for i in range(REQ_PER_THREAD):
+        req()
+
+@check_leak
+def run():
+    th = [threading.Thread(target=run_in_thread) for i in range(THREADS_NUM)]
+    for t in th:
+        t.start()
+    for t in th:
+        t.join()
+
+
+if __name__ == "__main__":
+    run_test(create_route, run)
+
diff --git a/t/fuzzing/upstream/nginx.conf b/t/fuzzing/upstream/nginx.conf
index 3c6405370..7a94517ce 100644
--- a/t/fuzzing/upstream/nginx.conf
+++ b/t/fuzzing/upstream/nginx.conf
@@ -53,6 +53,23 @@ http {
                 ngx.sleep(tonumber(ngx.var.arg_seconds or 1))
             }
         }
+
+        location /server_addr {
+            content_by_lua_block {
+                ngx.say(ngx.var.server_addr)
+            }
+        }
     }
 
+    server {
+        listen 6667 ssl;
+        ssl_certificate ../../certs/apisix.crt;
+        ssl_certificate_key ../../certs/apisix.key;
+
+        location /server_addr {
+            content_by_lua_block {
+                ngx.say(ngx.var.server_addr)
+            }
+        }
+    }
 }