|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +use t::APISIX 'no_plan'; |
| 18 | + |
| 19 | +repeat_each(1); |
| 20 | +log_level('info'); |
| 21 | +worker_connections(256); |
| 22 | +no_root_location(); |
| 23 | +no_shuffle(); |
| 24 | + |
| 25 | +run_tests(); |
| 26 | + |
| 27 | +__DATA__ |
| 28 | +
|
| 29 | +=== TEST 1: using route with an upstream id reference should also trigger healthcheck_manager |
| 30 | +--- extra_init_by_lua |
| 31 | + local utils = require("apisix.core.utils") |
| 32 | + local count = 0 |
| 33 | + utils.dns_parse = function (domain) -- mock: DNS parser |
| 34 | +
|
| 35 | + count = count + 1 |
| 36 | + if domain == "test1.com" then |
| 37 | + return {address = "127.0.0." .. count} |
| 38 | + end |
| 39 | + if domain == "test2.com" then |
| 40 | + return {address = "127.0.0." .. count+100} |
| 41 | + end |
| 42 | +
|
| 43 | + error("unknown domain: " .. domain) |
| 44 | + end |
| 45 | +--- config |
| 46 | + location /t { |
| 47 | + content_by_lua_block { |
| 48 | + local t = require("lib.test_admin").test |
| 49 | + local code, body = t('/apisix/admin/upstreams/1', |
| 50 | + ngx.HTTP_PUT, |
| 51 | + [[{ |
| 52 | + "nodes": { |
| 53 | + "test1.com:1980": 1, |
| 54 | + "test2.com:1980": 1 |
| 55 | + }, |
| 56 | + "type": "roundrobin", |
| 57 | + "desc": "new upstream", |
| 58 | + "checks": { |
| 59 | + "active": { |
| 60 | + "http_path": "/status", |
| 61 | + "healthy": { |
| 62 | + "interval": 1, |
| 63 | + "successes": 4 |
| 64 | + }, |
| 65 | + "unhealthy": { |
| 66 | + "interval": 1, |
| 67 | + "http_failures": 1 |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + }]] |
| 72 | + ) |
| 73 | +
|
| 74 | + if code >= 300 then |
| 75 | + ngx.status = code |
| 76 | + return |
| 77 | + end |
| 78 | +
|
| 79 | + code, body = t('/apisix/admin/routes/1', |
| 80 | + ngx.HTTP_PUT, |
| 81 | + [[{ |
| 82 | + "uri": "/hello", |
| 83 | + "upstream_id": "1" |
| 84 | + }]] |
| 85 | + ) |
| 86 | +
|
| 87 | + if code >= 300 then |
| 88 | + ngx.status = code |
| 89 | + return |
| 90 | + end |
| 91 | +
|
| 92 | + for _, _ in ipairs({1, 2, 3, 4, 5}) do |
| 93 | + code, body = t('/hello', ngx.HTTP_GET) |
| 94 | + if code >= 300 then |
| 95 | + ngx.status = code |
| 96 | + return |
| 97 | + end |
| 98 | + ngx.sleep(1) |
| 99 | + end |
| 100 | + ngx.say(body) |
| 101 | + } |
| 102 | + } |
| 103 | +--- timeout: 10 |
| 104 | +--- request |
| 105 | +GET /t |
| 106 | +--- response_body |
| 107 | +passed |
| 108 | +--- grep_error_log eval |
| 109 | +qr/create new checker: table:/ |
| 110 | +--- grep_error_log_out |
| 111 | +create new checker: table: |
| 112 | +create new checker: table: |
| 113 | +create new checker: table: |
| 114 | +create new checker: table: |
| 115 | +create new checker: table: |
0 commit comments