healthcheck-ipv6.t 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. BEGIN {
  18. if ($ENV{TEST_NGINX_CHECK_LEAK}) {
  19. $SkipReason = "unavailable for the hup tests";
  20. } else {
  21. $ENV{TEST_NGINX_USE_HUP} = 1;
  22. undef $ENV{TEST_NGINX_USE_STAP};
  23. }
  24. }
  25. use t::APISIX 'no_plan';
  26. repeat_each(1);
  27. log_level('info');
  28. no_root_location();
  29. no_shuffle();
  30. worker_connections(256);
  31. add_block_preprocessor(sub {
  32. my $block = shift;
  33. $block->set_value("listen_ipv6", 1);
  34. });
  35. run_tests();
  36. __DATA__
  37. === TEST 1: set route(two upstream node: one healthy + one unhealthy)
  38. --- config
  39. location /t {
  40. content_by_lua_block {
  41. local t = require("lib.test_admin").test
  42. local code, body = t('/apisix/admin/routes/1',
  43. ngx.HTTP_PUT,
  44. [[{
  45. "uri": "/server_port",
  46. "upstream": {
  47. "type": "roundrobin",
  48. "nodes": {
  49. "127.0.0.1:1980": 1,
  50. "127.0.0.1:1970": 1
  51. },
  52. "checks": {
  53. "active": {
  54. "http_path": "/status",
  55. "host": "foo.com",
  56. "healthy": {
  57. "interval": 1,
  58. "successes": 1
  59. },
  60. "unhealthy": {
  61. "interval": 1,
  62. "http_failures": 1
  63. }
  64. }
  65. }
  66. }
  67. }]]
  68. )
  69. if code >= 300 then
  70. ngx.status = code
  71. end
  72. ngx.say(body)
  73. }
  74. }
  75. --- request
  76. GET /t
  77. --- response_body
  78. passed
  79. --- grep_error_log eval
  80. qr/^.*?\[error\](?!.*process exiting).*/
  81. --- grep_error_log_out
  82. === TEST 2: hit routes (two upstream node: one healthy + one unhealthy)
  83. --- config
  84. location /t {
  85. content_by_lua_block {
  86. ngx.sleep(3) -- wait for new workers replacement to complete
  87. local http = require "resty.http"
  88. local uri = "http://127.0.0.1:" .. ngx.var.server_port
  89. .. "/server_port"
  90. do
  91. local httpc = http.new()
  92. local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false})
  93. ngx.log(ngx.ERR, "It works")
  94. end
  95. ngx.sleep(2.5)
  96. local ports_count = {}
  97. for i = 1, 12 do
  98. ngx.log(ngx.ERR, "req ", i)
  99. local httpc = http.new()
  100. local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false})
  101. if not res then
  102. ngx.say(err)
  103. return
  104. end
  105. ngx.log(ngx.ERR, "req ", i, " ", res.body)
  106. ports_count[res.body] = (ports_count[res.body] or 0) + 1
  107. end
  108. local ports_arr = {}
  109. for port, count in pairs(ports_count) do
  110. table.insert(ports_arr, {port = port, count = count})
  111. end
  112. local function cmd(a, b)
  113. return a.port > b.port
  114. end
  115. table.sort(ports_arr, cmd)
  116. ngx.say(require("toolkit.json").encode(ports_arr))
  117. ngx.exit(200)
  118. }
  119. }
  120. --- request
  121. GET /t
  122. --- response_body
  123. [{"count":12,"port":"1980"}]
  124. --- grep_error_log eval
  125. qr/unhealthy .* for '.*'/
  126. --- grep_error_log_out
  127. unhealthy TCP increment (1/2) for 'foo.com(127.0.0.1:1970)'
  128. unhealthy TCP increment (2/2) for 'foo.com(127.0.0.1:1970)'
  129. --- timeout: 10