healthcheck-leak-bugfix.t 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. repeat_each(1);
  19. log_level('warn');
  20. no_root_location();
  21. no_shuffle();
  22. run_tests();
  23. __DATA__
  24. === TEST 1: ensure the old check is cleared after configuration updated
  25. --- extra_init_worker_by_lua
  26. local healthcheck = require("resty.healthcheck")
  27. local new = healthcheck.new
  28. healthcheck.new = function(...)
  29. local obj = new(...)
  30. local clear = obj.delayed_clear
  31. obj.delayed_clear = function(...)
  32. ngx.log(ngx.WARN, "clear checker")
  33. return clear(...)
  34. end
  35. return obj
  36. end
  37. --- extra_init_by_lua
  38. local utils = require("apisix.core.utils")
  39. local count = 0
  40. utils.dns_parse = function (domain) -- mock: DNS parser
  41. count = count + 1
  42. if domain == "test1.com" then
  43. return {address = "127.0.0." .. count}
  44. end
  45. if domain == "test2.com" then
  46. return {address = "127.0.0." .. count+100}
  47. end
  48. error("unknown domain: " .. domain)
  49. end
  50. --- config
  51. location /t {
  52. content_by_lua_block {
  53. local cfg = [[{
  54. "upstream": {
  55. "nodes": {
  56. "test1.com:1980": 1,
  57. "test2.com:1980": 1
  58. },
  59. "type": "roundrobin",
  60. "checks":{
  61. "active":{
  62. "healthy":{
  63. "http_statuses":[
  64. 200,
  65. 302
  66. ],
  67. "interval":1,
  68. "successes":2
  69. },
  70. "http_path":"/hello",
  71. "timeout":1,
  72. "type":"http",
  73. "unhealthy":{
  74. "http_failures":5,
  75. "http_statuses":[
  76. 429,
  77. 404,
  78. 500,
  79. 501,
  80. 502,
  81. 503,
  82. 504,
  83. 505
  84. ],
  85. "interval":1,
  86. "tcp_failures":2,
  87. "timeouts":3
  88. }
  89. }
  90. }
  91. },
  92. "uri": "/hello"
  93. }]]
  94. local t = require("lib.test_admin").test
  95. assert(t('/apisix/admin/routes/1', ngx.HTTP_PUT, cfg) < 300)
  96. t('/hello', ngx.HTTP_GET)
  97. assert(t('/apisix/admin/routes/1', ngx.HTTP_PUT, cfg) < 300)
  98. ngx.sleep(1)
  99. }
  100. }
  101. --- request
  102. GET /t
  103. --- error_log
  104. clear checker