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

baoyuan 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 d89cb868b change: remove lua-resty-worker-events (#12930)
d89cb868b is described below

commit d89cb868bd5634b810b9e03d61ec7d515b03cab1
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Mon Jan 26 14:04:17 2026 +0545

    change: remove lua-resty-worker-events (#12930)
---
 .github/workflows/build.yml                     |   4 -
 .github/workflows/redhat-ci.yaml                |   6 +-
 apisix-master-0.rockspec                        |   1 -
 apisix/cli/config.lua                           |   3 -
 apisix/cli/ngx_tpl.lua                          |   4 -
 apisix/events.lua                               |  66 +----
 apisix/healthcheck_manager.lua                  |   3 +-
 ci/linux_openresty_common_runner.sh             |   2 +-
 ci/redhat-ci.sh                                 |   2 +-
 conf/config.yaml.example                        |   3 -
 t/APISIX.pm                                     |   2 -
 t/node/healthcheck-passive.t                    | 373 ------------------------
 t/plugin/ai-proxy-multi3.t                      | 120 +++++---
 t/stream-node/healthcheck-resty-worker-events.t | 283 ------------------
 14 files changed, 87 insertions(+), 785 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a4898117b..f8dc0040d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -28,9 +28,6 @@ jobs:
           - ubuntu-latest
         os_name:
           - linux_openresty
-        events_module:
-          - lua-resty-worker-events
-          - lua-resty-events
         test_dir:
           - t/plugin/[a-k]*.t
           - t/stream-plugin t/plugin/[l-z]*.t
@@ -170,7 +167,6 @@ jobs:
       - name: Linux Script
         env:
           TEST_FILE_SUB_DIR: ${{ matrix.test_dir }}
-          TEST_EVENTS_MODULE: ${{ matrix.events_module }}
         run: sudo -E ./ci/${{ matrix.os_name }}_runner.sh script
 
       - if: ${{ steps.cache-images.outputs.cache-hit != 'true' }}
diff --git a/.github/workflows/redhat-ci.yaml b/.github/workflows/redhat-ci.yaml
index 9de1b0b75..9304c5dd3 100644
--- a/.github/workflows/redhat-ci.yaml
+++ b/.github/workflows/redhat-ci.yaml
@@ -23,9 +23,6 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        events_module:
-          - lua-resty-worker-events
-          - lua-resty-events
         test_dir:
           - t/plugin/[a-k]*
           - t/plugin/[l-z]*
@@ -120,9 +117,8 @@ jobs:
     - name: Run redhat docker and mapping apisix into container
       env:
         TEST_FILE_SUB_DIR: ${{ matrix.test_dir }}
-        TEST_EVENTS_MODULE: ${{ matrix.events_module }}
       run: |
-        docker run -itd -v ${{ github.workspace }}:/apisix --env 
TEST_FILE_SUB_DIR="$TEST_FILE_SUB_DIR" --env 
TEST_EVENTS_MODULE="$TEST_EVENTS_MODULE" --name ubiInstance --net="host" --dns 
8.8.8.8 --dns-search apache.org registry.access.redhat.com/ubi8/ubi:8.6 
/bin/bash
+        docker run -itd -v ${{ github.workspace }}:/apisix --env 
TEST_FILE_SUB_DIR="$TEST_FILE_SUB_DIR" --name ubiInstance --net="host" --dns 
8.8.8.8 --dns-search apache.org registry.access.redhat.com/ubi8/ubi:8.6 
/bin/bash
 
     - name: Cache images
       id: cache-images
diff --git a/apisix-master-0.rockspec b/apisix-master-0.rockspec
index 96b37f482..ecc2b56b8 100644
--- a/apisix-master-0.rockspec
+++ b/apisix-master-0.rockspec
@@ -41,7 +41,6 @@ dependencies = {
     "lua-resty-ngxvar = 0.5.2-0",
     "lua-resty-jit-uuid = 0.0.7-2",
     "lua-resty-ksuid = 1.0.1-0",
-    "lua-resty-worker-events = 1.0.0",
     "lua-resty-healthcheck-api7 = 3.2.0-0",
     "api7-lua-resty-jwt = 0.2.6-0",
     "lua-resty-hmac-ffi = 0.06-1",
diff --git a/apisix/cli/config.lua b/apisix/cli/config.lua
index 1dd9364f4..6212e53c3 100644
--- a/apisix/cli/config.lua
+++ b/apisix/cli/config.lua
@@ -77,9 +77,6 @@ local _M = {
       enable_encrypt_fields = true,
       keyring = { "qeddd145sfvddff3", "edd1c9f0985e76a2" }
     },
-    events = {
-      module = "lua-resty-events"
-    },
     lru = {
       secret = {
         ttl = 300,
diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
index e82b70b04..d5631c0a5 100644
--- a/apisix/cli/ngx_tpl.lua
+++ b/apisix/cli/ngx_tpl.lua
@@ -212,7 +212,6 @@ stream {
         apisix.stream_init_worker()
     }
 
-    {% if (events.module or "") == "lua-resty-events" then %}
     # the server block for lua-resty-events
     server {
         listen unix:{*apisix_lua_home*}/logs/stream_worker_events.sock;
@@ -221,7 +220,6 @@ stream {
             require("resty.events.compat").run()
         }
     }
-    {% end %}
 
     server {
         {% for _, item in ipairs(stream_proxy.tcp or {}) do %}
@@ -533,7 +531,6 @@ http {
         apisix.http_exit_worker()
     }
 
-    {% if (events.module or "") == "lua-resty-events" then %}
     # the server block for lua-resty-events
     server {
         listen unix:{*apisix_lua_home*}/logs/worker_events.sock;
@@ -544,7 +541,6 @@ http {
             }
         }
     }
-    {% end %}
 
     {% if enable_control then %}
     server {
diff --git a/apisix/events.lua b/apisix/events.lua
index a38129d86..aeb31af8a 100644
--- a/apisix/events.lua
+++ b/apisix/events.lua
@@ -25,32 +25,10 @@ local ngx          = ngx
 local core         = require("apisix.core")
 
 local _M = {
-    events_module = nil,
 }
 
-_M.EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS = 'lua-resty-worker-events'
-_M.EVENTS_MODULE_LUA_RESTY_EVENTS = 'lua-resty-events'
-
-
--- use lua-resty-worker-events
-local function init_resty_worker_events()
-    _M.events_module = _M.EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS
-
-    local we = require("resty.worker.events")
-    local shm = ngx.config.subsystem == "http" and "worker-events" or 
"worker-events-stream"
-    local ok, err = we.configure({shm = shm, interval = 0.1})
-    if not ok then
-        error("failed to init worker event: " .. err)
-    end
-
-    return we
-end
-
-
 -- use lua-resty-events
 local function init_resty_events()
-    _M.events_module = _M.EVENTS_MODULE_LUA_RESTY_EVENTS
-
     local listening = "unix:" .. ngx.config.prefix() .. "logs/"
     if ngx.config.subsystem == "http" then
         listening = listening .. "worker_events.sock"
@@ -81,19 +59,7 @@ function _M.init_worker()
     end
 
     _M.inited = true
-
-    local conf = core.config.local_conf()
-    local module_name = core.table.try_read_attr(conf, "apisix", "events", 
"module")
-                            or _M.EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS
-
-    if module_name == _M.EVENTS_MODULE_LUA_RESTY_EVENTS then
-        -- use lua-resty-events as an event module via the apisix.events.module
-        -- key in the configuration file
-        _M.worker_events = init_resty_events()
-    else
-        -- use lua-resty-worker-events default now
-        _M.worker_events = init_resty_worker_events()
-    end
+    _M.worker_events = init_resty_events()
 end
 
 
@@ -105,20 +71,15 @@ end
 function _M.event_list(self, source, ...)
     -- a patch for the lua-resty-events to support event_list
     -- this snippet is copied from the lua-resty-worker-events lib
-    if self.events_module == _M.EVENTS_MODULE_LUA_RESTY_EVENTS then
-        local events = { _source = source }
-        for _, event in pairs({...}) do
-            events[event] = event
-        end
-        return setmetatable(events, {
-            __index = function(_, key)
-            error("event '"..tostring(key).."' is an unknown event", 2)
-            end
-        })
+    local events = { _source = source }
+    for _, event in pairs({...}) do
+        events[event] = event
     end
-
-    -- the lua-resty-worker-events has a built-in event_list implementation
-    return self.worker_events.event_list(source, ...)
+    return setmetatable(events, {
+        __index = function(_, key)
+        error("event '"..tostring(key).."' is an unknown event", 2)
+        end
+    })
 end
 
 
@@ -127,13 +88,4 @@ function _M.post(self, ...)
 end
 
 
-function _M.get_healthcheck_events_module(self)
-    if self.events_module == _M.EVENTS_MODULE_LUA_RESTY_EVENTS then
-        return "resty.events"
-    else
-        return "resty.worker.events"
-    end
-end
-
-
 return _M
diff --git a/apisix/healthcheck_manager.lua b/apisix/healthcheck_manager.lua
index d7d3280a0..bc27bdb8e 100644
--- a/apisix/healthcheck_manager.lua
+++ b/apisix/healthcheck_manager.lua
@@ -25,7 +25,6 @@ local config_local   = require("apisix.core.config_local")
 local resource = require("apisix.resource")
 local upstream_utils = require("apisix.utils.upstream")
 local healthcheck
-local events = require("apisix.events")
 local tab_clone = core.table.clone
 local timer_every = ngx.timer.every
 local jp = require("jsonpath")
@@ -67,7 +66,7 @@ local function create_checker(up_conf)
         name = get_healthchecker_name(up_conf),
         shm_name = healthcheck_shdict_name,
         checks = up_conf.checks,
-        events_module = events:get_healthcheck_events_module(),
+        events_module = "resty.events",
     })
 
     if not checker then
diff --git a/ci/linux_openresty_common_runner.sh 
b/ci/linux_openresty_common_runner.sh
index 99250a6d5..540e6e81f 100755
--- a/ci/linux_openresty_common_runner.sh
+++ b/ci/linux_openresty_common_runner.sh
@@ -92,7 +92,7 @@ script() {
     start_sse_server_example
 
     # APISIX_ENABLE_LUACOV=1 PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t
-    FLUSH_ETCD=1 TEST_EVENTS_MODULE=$TEST_EVENTS_MODULE prove --timer 
-Itest-nginx/lib -I./ -r $TEST_FILE_SUB_DIR | tee /tmp/test.result
+    FLUSH_ETCD=1 prove --timer -Itest-nginx/lib -I./ -r $TEST_FILE_SUB_DIR | 
tee /tmp/test.result
     fail_on_bailout /tmp/test.result
     rerun_flaky_tests /tmp/test.result
 }
diff --git a/ci/redhat-ci.sh b/ci/redhat-ci.sh
index 06c0bee10..97492a6e6 100755
--- a/ci/redhat-ci.sh
+++ b/ci/redhat-ci.sh
@@ -101,7 +101,7 @@ run_case() {
     make init
     set_coredns
     # run test cases
-    FLUSH_ETCD=1 TEST_EVENTS_MODULE=$TEST_EVENTS_MODULE prove --timer 
-Itest-nginx/lib -I./ -r ${TEST_FILE_SUB_DIR} | tee /tmp/test.result
+    FLUSH_ETCD=1 prove --timer -Itest-nginx/lib -I./ -r ${TEST_FILE_SUB_DIR} | 
tee /tmp/test.result
     fail_on_bailout /tmp/test.result
     rerun_flaky_tests /tmp/test.result
 }
diff --git a/conf/config.yaml.example b/conf/config.yaml.example
index 139e30edc..67fd190d8 100644
--- a/conf/config.yaml.example
+++ b/conf/config.yaml.example
@@ -132,9 +132,6 @@ apisix:
                                   # with the new key. Removing the old keys 
directly can render the data
                                   # unrecoverable.
 
-  events:                             # Event distribution module configuration
-    module: lua-resty-events          # Sets the name of the events module 
used.
-                                      # Supported module: 
lua-resty-worker-events and lua-resty-events
 # status:                       # When enabled, APISIX will provide `/status` 
and `/status/ready` endpoints
   #   ip: 127.0.0.1               # /status endpoint will return 200 status 
code if APISIX has successfully started and running correctly
   #   port: 7085                  # /status/ready endpoint will return 503 
status code if any of the workers do not receive config from etcd
diff --git a/t/APISIX.pm b/t/APISIX.pm
index 40bf590a1..f89955163 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -78,14 +78,12 @@ if ($custom_dns_server) {
 }
 
 
-my $events_module = $ENV{TEST_EVENTS_MODULE} // "lua-resty-events";
 my $test_default_config = <<_EOC_;
     -- read the default configuration, modify it, and the Lua package
     -- cache will persist it for loading by other entrypoints
     -- it is used to replace the test::nginx implementation
     local default_config = require("apisix.cli.config")
     default_config.plugin_attr.prometheus.enable_export_server = false
-    default_config.apisix.events.module = "$events_module"
 _EOC_
 
 my $user_yaml_config = read_file("conf/config.yaml");
diff --git a/t/node/healthcheck-passive.t b/t/node/healthcheck-passive.t
deleted file mode 100644
index 8de3eab8d..000000000
--- a/t/node/healthcheck-passive.t
+++ /dev/null
@@ -1,373 +0,0 @@
-#
-# 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.
-#
-
-BEGIN {
-    if ($ENV{TEST_EVENTS_MODULE} ne "lua-resty-worker-events") {
-        $SkipReason = "Only for lua-resty-worker-events events module";
-    }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-use t::APISIX 'no_plan';
-
-repeat_each(1);
-log_level('info');
-no_root_location();
-no_shuffle();
-worker_connections(256);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: set route(passive)
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/routes/1',
-                ngx.HTTP_PUT,
-                [[{
-                    "uri": "/server_port",
-                    "upstream": {
-                        "type": "roundrobin",
-                        "nodes": {
-                            "127.0.0.1:1980": 0,
-                            "127.0.0.1:1": 1
-                        },
-                        "retries": 0,
-                        "checks": {
-                            "active": {
-                                "http_path": "/status",
-                                "host": "foo.com",
-                                "healthy": {
-                                    "interval": 100,
-                                    "successes": 1
-                                },
-                                "unhealthy": {
-                                    "interval": 100,
-                                    "http_failures": 2
-                                }
-                            },]] .. [[
-                            "passive": {
-                                "healthy": {
-                                    "http_statuses": [200, 201],
-                                    "successes": 3
-                                },
-                                "unhealthy": {
-                                    "http_statuses": [502],
-                                    "http_failures": 1,
-                                    "tcp_failures": 1
-                                }
-                            }
-                        }
-                    }
-                }]]
-                )
-
-            if code >= 300 then
-                ngx.status = code
-            end
-            ngx.say(body)
-        }
-    }
---- request
-GET /t
---- response_body
-passed
-
-
-
-=== TEST 2: hit routes (two healthy nodes)
---- config
-    location /t {
-        content_by_lua_block {
-            ngx.sleep(2) -- wait for sync
-
-            local json_sort = require("toolkit.json")
-            local http = require("resty.http")
-            local uri = "http://127.0.0.1:"; .. ngx.var.server_port .. 
"/server_port"
-            --- trigger the passive healthcheck
-            local httpc = http.new()
-            local res, err = httpc:request_uri(uri, {method = "GET", keepalive 
= false})
-            if not res then
-                ngx.say(err)
-                return
-            end
-            ngx.sleep(3)
-            local ports_count = {}
-            for i = 1, 6 do
-                local httpc = http.new()
-                local res, err = httpc:request_uri(uri, {method = "GET", 
keepalive = false})
-                if not res then
-                    ngx.say(err)
-                    return
-                end
-
-                local status = tostring(res.status)
-                ports_count[status] = (ports_count[status] or 0) + 1
-            end
-
-            ngx.say(json_sort.encode(ports_count))
-            ngx.exit(200)
-        }
-    }
---- request
-GET /t
---- response_body
-{"200":5,"502":1}
---- error_log
-(upstream#/apisix/routes/1) unhealthy HTTP increment (1/1)
---- timeout: 7
-
-
-
-=== TEST 3: set route(only passive)
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/routes/1',
-                ngx.HTTP_PUT,
-                [[{
-                    "uri": "/server_port",
-                    "upstream": {
-                        "type": "roundrobin",
-                        "nodes": {
-                            "127.0.0.1:1980": 0,
-                            "127.0.0.1:1": 1
-                        },
-                        "retries": 0,
-                        "checks": {
-                            "passive": {
-                                "healthy": {
-                                    "http_statuses": [200, 201],
-                                    "successes": 3
-                                },
-                                "unhealthy": {
-                                    "http_statuses": [502],
-                                    "http_failures": 1,
-                                    "tcp_failures": 1
-                                }
-                            }
-                        }
-                    }
-                }]]
-                )
-
-            if code >= 300 then
-                ngx.status = code
-            end
-            ngx.print(body)
-        }
-    }
---- request
-GET /t
---- error_code: 400
---- response_body
-{"error_msg":"invalid configuration: property \"upstream\" validation failed: 
property \"checks\" validation failed: object matches none of the required: 
[\"active\"] or [\"active\",\"passive\"]"}
-
-
-
-=== TEST 4: set route(only active + active & passive)
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/routes/1',
-                ngx.HTTP_PUT,
-                [[{
-                    "uri": "/hello",
-                    "upstream": {
-                        "type": "roundrobin",
-                        "nodes": {
-                            "127.0.0.1:1980": 0,
-                            "127.0.0.1:1": 1
-                        },
-                        "retries": 0,
-                        "checks": {
-                            "active": {
-                                "http_path": "/status",
-                                "host": "foo.com",
-                                "healthy": {
-                                    "interval": 100,
-                                    "successes": 1
-                                },
-                                "unhealthy": {
-                                    "interval": 100,
-                                    "http_failures": 2
-                                }
-                            }
-                        }
-                    }
-                }]]
-                )
-
-            if code >= 300 then
-                ngx.status = code
-                ngx.say(body)
-                return
-            end
-
-            local code, body = t('/apisix/admin/routes/2',
-                ngx.HTTP_PUT,
-                [[{
-                    "uri": "/hello_",
-                    "upstream": {
-                        "type": "roundrobin",
-                        "nodes": {
-                            "127.0.0.1:1980": 0,
-                            "127.0.0.1:1": 1
-                        },
-                        "retries": 0,
-                        "checks": {
-                            "active": {
-                                "http_path": "/status",
-                                "host": "foo.com",
-                                "healthy": {
-                                    "interval": 100,
-                                    "successes": 1
-                                },
-                                "unhealthy": {
-                                    "interval": 100,
-                                    "http_failures": 2
-                                }
-                            },]] .. [[
-                            "passive": {
-                                "healthy": {
-                                    "http_statuses": [200, 201],
-                                    "successes": 3
-                                },
-                                "unhealthy": {
-                                    "http_statuses": [502],
-                                    "http_failures": 1,
-                                    "tcp_failures": 1
-                                }
-                            }
-                        }
-                    }
-                }]]
-                )
-
-            if code >= 300 then
-                ngx.status = code
-            end
-            ngx.say(body)
-        }
-    }
---- request
-GET /t
---- response_body
-passed
-
-
-
-=== TEST 5: only one route should have passive healthcheck
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local json_sort = require("toolkit.json")
-            local http = require("resty.http")
-            local uri = "http://127.0.0.1:"; .. ngx.var.server_port
-
-            local ports_count = {}
-            local httpc = http.new()
-            local res, err = httpc:request_uri(uri .. "/hello_")
-            if not res then
-                ngx.say(err)
-                return
-            end
-            ngx.say(res.status)
-            ngx.sleep(2)
-            --- The first request above triggers the passive healthcheck
-            --- The healthchecker is asynchronously created after a minimum of 
1 second
-            --- So we need to wait for it to be created and sent another 
request to verify
-            -- only /hello_ has passive healthcheck
-            local res, err = httpc:request_uri(uri .. "/hello_")
-            if not res then
-                ngx.say(err)
-                return
-            end
-            ngx.sleep(2)
-            -- only /hello_ has passive healthcheck
-            local res, err = httpc:request_uri(uri .. "/hello")
-            if not res then
-                ngx.say(err)
-                return
-            end
-            ngx.say(res.status)
-        }
-    }
---- request
-GET /t
---- response_body
-502
-502
---- grep_error_log eval
-qr/enabled healthcheck passive/
---- grep_error_log_out
-enabled healthcheck passive
---- timeout: 7
-
-
-
-=== TEST 6: make sure passive healthcheck works (conf is not corrupted by the 
default value)
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local json_sort = require("toolkit.json")
-            local http = require("resty.http")
-            local uri = "http://127.0.0.1:"; .. ngx.var.server_port
-
-            local ports_count = {}
-            local httpc = http.new()
-            local res, err = httpc:request_uri(uri .. "/hello")
-            if not res then
-                ngx.say(err)
-                return
-            end
-            ngx.say(res.status)
-
-            local res, err = httpc:request_uri(uri .. "/hello_")
-            if not res then
-                ngx.say(err)
-                return
-            end
-            ngx.sleep(2)
-            --- The first request above triggers the passive healthcheck
-            --- The healthchecker is asynchronously created after a minimum of 
1 second
-            --- So we need to wait for it to be created and sent another 
request to verify
-            -- only /hello_ has passive healthcheck
-            local res, err = httpc:request_uri(uri .. "/hello_")
-            if not res then
-                ngx.say(err)
-                return
-            end
-            ngx.say(res.status)
-        }
-    }
---- request
-GET /t
---- response_body
-502
-502
---- grep_error_log eval
-qr/\[healthcheck\] \([^)]+\) unhealthy HTTP increment/
---- grep_error_log_out
-[healthcheck] (upstream#/apisix/routes/2) unhealthy HTTP increment
diff --git a/t/plugin/ai-proxy-multi3.t b/t/plugin/ai-proxy-multi3.t
index 33f317d63..dfb95d8a2 100644
--- a/t/plugin/ai-proxy-multi3.t
+++ b/t/plugin/ai-proxy-multi3.t
@@ -15,11 +15,6 @@
 # limitations under the License.
 #
 
-BEGIN {
-    if ($ENV{TEST_EVENTS_MODULE} ne "lua-resty-worker-events") {
-        $SkipReason = "Only for lua-resty-worker-events events module";
-    }
-}
 use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
 use t::APISIX 'no_plan';
 
@@ -933,51 +928,84 @@ POST /ai
                 return original_parse_domain(host)
             end
             -- Create a route with health check that uses the domain
-            local code, body = t('/apisix/admin/routes/1',
-                 ngx.HTTP_PUT,
-                 [[{
-                    "uri": "/ai",
-                    "plugins": {
-                        "ai-proxy-multi": {
-                            "instances": [
-                                {
-                                    "name": "openai-test",
-                                    "provider": "openai",
-                                    "weight": 1,
-                                    "priority": 1,
-                                    "auth": {
-                                        "header": {
-                                            "Authorization": "Bearer token"
-                                        }
-                                    },
-                                    "options": {
-                                        "model": "gpt-4"
-                                    },
-                                    "override": {
-                                        "endpoint": 
"http://test.example.com:16724";
-                                    },
-                                    "checks": {
-                                        "active": {
-                                            "timeout": 5,
-                                            "http_path": "/status/test",
-                                            "host": "test.example.com",
-                                            "healthy": {
-                                                "interval": 1,
-                                                "successes": 1
-                                            },
-                                            "unhealthy": {
-                                                "interval": 1,
-                                                "http_failures": 1
-                                            }
+            local core = require("apisix.core")
+            local route_config = {
+                uri = "/ai",
+                plugins = {
+                    ["ai-proxy-multi"] = {
+                        instances = {
+                            {
+                                name = "openai-test",
+                                provider = "openai",
+                                weight = 1,
+                                priority = 1,
+                                auth = {
+                                    header = {
+                                        Authorization = "Bearer token"
+                                    }
+                                },
+                                options = {
+                                    model = "gpt-4"
+                                },
+                                override = {
+                                    endpoint = "http://test.example.com:16724";
+                                },
+                                checks = {
+                                    active = {
+                                        timeout = 5,
+                                        http_path = "/status/test",
+                                        host = "test.example.com",
+                                        healthy = {
+                                            interval = 1,
+                                            successes = 1
+                                        },
+                                        unhealthy = {
+                                            interval = 1,
+                                            http_failures = 1
                                         }
                                     }
+                                }
+                            },
+                            {
+                                name = "openai-test-2",
+                                provider = "openai",
+                                weight = 1,
+                                priority = 1,
+                                auth = {
+                                    header = {
+                                        Authorization = "Bearer token"
+                                    }
                                 },
-                                {"name": "openai-test-2","provider": 
"openai","weight": 1,"priority": 1,"auth": {"header": {"Authorization": "Bearer 
token"}},"options": {"model": "gpt-4"},"override": {"endpoint": 
"http://test.example.com:16724"},"checks": {"active": {"timeout": 
5,"http_path": "/status/test","host": "test.example.com","healthy": 
{"interval": 1,"successes": 1},"unhealthy": {"interval": 1,"http_failures": 
1}}}}
-                            ],
-                            "ssl_verify": false
-                        }
+                                options = {
+                                    model = "gpt-4"
+                                },
+                                override = {
+                                    endpoint = "http://test.example.com:16724";
+                                },
+                                checks = {
+                                    active = {
+                                        timeout = 5,
+                                        http_path = "/status/test",
+                                        host = "test.example.com",
+                                        healthy = {
+                                            interval = 1,
+                                            successes = 1
+                                        },
+                                        unhealthy = {
+                                            interval = 1,
+                                            http_failures = 1
+                                        }
+                                    }
+                                }
+                            }
+                        },
+                        ssl_verify = false
                     }
-                }]]
+                }
+            }
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 core.json.encode(route_config)
             )
             if code >= 300 then
                 ngx.status = code
diff --git a/t/stream-node/healthcheck-resty-worker-events.t 
b/t/stream-node/healthcheck-resty-worker-events.t
deleted file mode 100644
index 923b36603..000000000
--- a/t/stream-node/healthcheck-resty-worker-events.t
+++ /dev/null
@@ -1,283 +0,0 @@
-# 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.
-BEGIN {
-    if ($ENV{TEST_EVENTS_MODULE} ne "lua-resty-worker-events") {
-        $SkipReason = "Only for lua-resty-worker-events events module";
-    }
-}
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-use t::APISIX 'no_plan';
-
-log_level('info');
-no_root_location();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: create stream route with a upstream that enable active healthcheck 
only, \
-            two upstream nodes: one healthy + one unhealthy, unhealthy node 
with high priority
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/stream_routes/1',
-                ngx.HTTP_PUT,
-                [[{
-                    "remote_addr": "127.0.0.1",
-                    "upstream": {
-                        "nodes": [
-                            { "host": "127.0.0.1", "port": 1995, "weight": 
100, "priority": 0 },
-                            { "host": "127.0.0.1", "port": 9995, "weight": 
100, "priority": 1 }
-                        ],
-                        "type": "roundrobin",
-                        "retries": 0,
-                        "checks": {
-                            "active": {
-                                "type": "tcp",
-                                "timeout": 1,
-                                "healthy": {
-                                    "interval": 1,
-                                    "successes": 2
-                                },
-                                "unhealthy": {
-                                    "interval": 1,
-                                    "tcp_failures": 1,
-                                    "timeouts": 1
-                                }
-                            }
-                        }
-                    }
-                }]]
-            )
-            if code >= 300 then
-                ngx.status = code
-            end
-            ngx.say(body)
-        }
-    }
---- request
-GET /t
---- response_body
-passed
-
-
-
-=== TEST 2: hit stream routes
---- stream_conf_enable
---- config
-    location /t {
-        content_by_lua_block {
-            -- send first request to create health checker
-            local sock = ngx.socket.tcp()
-            local ok, err = sock:connect("127.0.0.1", 1985)
-            if not ok then
-                ngx.say("failed to connect: ", err)
-                return
-            end
-            local data, _ = sock:receive()
-            assert(data == nil, "first request should fail")
-            sock:close()
-
-            -- wait for health check to take effect
-            ngx.sleep(4.5)
-
-            for i = 1, 3 do
-                local sock = ngx.socket.tcp()
-                local ok, err = sock:connect("127.0.0.1", 1985)
-                if not ok then
-                    ngx.say("failed to connect: ", err)
-                    return
-                end
-
-                local _, err = sock:send("mmm")
-                if err then
-                    ngx.say("failed to send: ", err)
-                    return
-                end
-
-                local data, err = sock:receive()
-                if err then
-                    ngx.say("failed to receive: ", err)
-                    return
-                end
-
-                assert(data == "hello world", "response should be 'hello 
world'")
-
-                sock:close()
-            end
-
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/stream_routes/1',
-                ngx.HTTP_DELETE
-            )
-
-            if code >= 300 then
-                ngx.status = code
-                ngs.say("failed to delete stream route")
-                return
-            end
-
-            -- wait for checker to release
-            ngx.sleep(1)
-
-            ngx.say("passed")
-        }
-    }
---- timeout: 10
---- request
-GET /t
---- response_body
-passed
---- error_log
-create new checker
-proxy request to 127.0.0.1:9995 while connecting to upstream
-connect() failed (111: Connection refused) while connecting to upstream, 
client: 127.0.0.1, server: 0.0.0.0:1985, upstream: "127.0.0.1:9995"
-unhealthy TCP increment (1/1) for '127.0.0.1(127.0.0.1:9995)'
-proxy request to 127.0.0.1:1995 while connecting to upstream
-proxy request to 127.0.0.1:1995 while connecting to upstream
-proxy request to 127.0.0.1:1995 while connecting to upstream
-try to release checker
-
-
-
-=== TEST 3: create stream route with a upstream that enable active and passive 
healthcheck, \
-            configure active healthcheck with a high unhealthy threshold, \
-            two upstream nodes: one healthy + one unhealthy, unhealthy node 
with high priority
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/stream_routes/1',
-                ngx.HTTP_PUT,
-                [[{
-                    "remote_addr": "127.0.0.1",
-                    "upstream": {
-                        "nodes": [
-                            { "host": "127.0.0.1", "port": 1995, "weight": 
100, "priority": 0 },
-                            { "host": "127.0.0.1", "port": 9995, "weight": 
100, "priority": 1 }
-                        ],
-                        "type": "roundrobin",
-                        "retries": 0,
-                        "checks": {
-                            "active": {
-                                "type": "tcp",
-                                "timeout": 1,
-                                "healthy": {
-                                    "interval": 60,
-                                    "successes": 2
-                                },
-                                "unhealthy": {
-                                    "interval": 1,
-                                    "tcp_failures": 254,
-                                    "timeouts": 1
-                                }
-                            },
-                            "passive": {
-                                "type": "tcp",
-                                "healthy": {
-                                    "successes": 1
-                                },
-                                "unhealthy": {
-                                    "tcp_failures": 1
-                                }
-                            }
-                        }
-                    }
-                }]]
-            )
-            if code >= 300 then
-                ngx.status = code
-            end
-            ngx.say(body)
-        }
-    }
---- request
-GET /t
---- response_body
-passed
-
-
-
-=== TEST 4: hit stream routes
---- stream_conf_enable
---- config
-    location /t {
-        content_by_lua_block {
-            local sock = ngx.socket.tcp()
-            local ok, err = sock:connect("127.0.0.1", 1985)
-            if not ok then
-                ngx.say("failed to connect: ", err)
-                return
-            end
-            local data, _ = sock:receive()
-            assert(data == nil, "first request should fail")
-            sock:close()
-            ngx.sleep(2)
-
-
-            local ok, err = sock:connect("127.0.0.1", 1985)
-            if not ok then
-                ngx.say("failed to connect: ", err)
-                return
-            end
-            local data, _ = sock:receive()
-            assert(data == nil, "one more request fail")
-            sock:close()
-            ngx.sleep(2)
-
-            for i = 1, 3 do
-                local sock = ngx.socket.tcp()
-                local ok, err = sock:connect("127.0.0.1", 1985)
-                if not ok then
-                    ngx.say("failed to connect: ", err)
-                    return
-                end
-
-                local _, err = sock:send("mmm")
-                if err then
-                    ngx.say("failed to send: ", err)
-                    return
-                end
-
-                local data, err = sock:receive()
-                if err then
-                    ngx.say("failed to receive: ", err)
-                    return
-                end
-
-                assert(data == "hello world", "response should be 'hello 
world'")
-
-                sock:close()
-            end
-
-            ngx.say("passed")
-        }
-    }
---- request
-GET /t
---- response_body
-passed
---- error_log
-proxy request to 127.0.0.1:9995 while connecting to upstream
-connect() failed (111: Connection refused) while connecting to upstream, 
client: 127.0.0.1, server: 0.0.0.0:1985, upstream: "127.0.0.1:9995"
-enabled healthcheck passive while connecting to upstream, client: 127.0.0.1, 
server: 0.0.0.0:1985, upstream: "127.0.0.1:9995",
-unhealthy TCP increment (1/1) for '(127.0.0.1:9995)' while connecting to 
upstream, client: 127.0.0.1, server: 0.0.0.0:1985, upstream: "127.0.0.1:9995",
-proxy request to 127.0.0.1:1995 while connecting to upstream
-proxy request to 127.0.0.1:1995 while connecting to upstream
-proxy request to 127.0.0.1:1995 while connecting to upstream
---- timeout: 10


Reply via email to