upstream-domain-with-special-dns.t 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. $ENV{CUSTOM_DNS_SERVER} = "127.0.0.1:1053";
  19. }
  20. use t::APISIX 'no_plan';
  21. repeat_each(1);
  22. log_level('info');
  23. no_root_location();
  24. no_shuffle();
  25. add_block_preprocessor(sub {
  26. my ($block) = @_;
  27. my $yaml_config = $block->yaml_config // <<_EOC_;
  28. apisix:
  29. node_listen: 1984
  30. deployment:
  31. role: data_plane
  32. role_data_plane:
  33. config_provider: yaml
  34. _EOC_
  35. $block->set_value("yaml_config", $yaml_config);
  36. my $routes = <<_EOC_;
  37. routes:
  38. -
  39. uri: /hello
  40. upstream_id: 1
  41. #END
  42. _EOC_
  43. $block->set_value("apisix_yaml", $block->apisix_yaml . $routes);
  44. });
  45. run_tests();
  46. __DATA__
  47. === TEST 1: AAAA
  48. --- listen_ipv6
  49. --- apisix_yaml
  50. upstreams:
  51. - id: 1
  52. nodes:
  53. ipv6.test.local:1980: 1
  54. type: roundrobin
  55. --- request
  56. GET /hello
  57. --- response_body
  58. hello world
  59. === TEST 2: default ttl
  60. --- log_level: debug
  61. --- apisix_yaml
  62. upstreams:
  63. - id: 1
  64. nodes:
  65. ttl.test.local:1980: 1
  66. type: roundrobin
  67. --- config
  68. location /t {
  69. content_by_lua_block {
  70. local http = require "resty.http"
  71. local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
  72. for i = 1, 3 do
  73. local httpc = http.new()
  74. local res, err = httpc:request_uri(uri, {method = "GET"})
  75. if not res or res.body ~= "hello world\n" then
  76. ngx.say(err)
  77. return
  78. end
  79. end
  80. }
  81. }
  82. --- request
  83. GET /t
  84. --- error_log
  85. "ttl":300
  86. --- grep_error_log eval
  87. qr/connect to 127.0.0.1:1053/
  88. --- grep_error_log_out
  89. connect to 127.0.0.1:1053
  90. === TEST 3: override ttl
  91. --- log_level: debug
  92. --- yaml_config
  93. apisix:
  94. node_listen: 1984
  95. dns_resolver_valid: 900
  96. deployment:
  97. role: data_plane
  98. role_data_plane:
  99. config_provider: yaml
  100. --- apisix_yaml
  101. upstreams:
  102. - id: 1
  103. nodes:
  104. ttl.test.local:1980: 1
  105. type: roundrobin
  106. --- config
  107. location /t {
  108. content_by_lua_block {
  109. local http = require "resty.http"
  110. local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
  111. for i = 1, 3 do
  112. local httpc = http.new()
  113. local res, err = httpc:request_uri(uri, {method = "GET"})
  114. if not res or res.body ~= "hello world\n" then
  115. ngx.say(err)
  116. return
  117. end
  118. end
  119. }
  120. }
  121. --- request
  122. GET /t
  123. --- grep_error_log eval
  124. qr/connect to 127.0.0.1:1053/
  125. --- grep_error_log_out
  126. connect to 127.0.0.1:1053
  127. --- error_log
  128. "ttl":900
  129. === TEST 4: cache expire
  130. --- log_level: debug
  131. --- apisix_yaml
  132. upstreams:
  133. - id: 1
  134. nodes:
  135. ttl.1s.test.local:1980: 1
  136. type: roundrobin
  137. --- config
  138. location /t {
  139. content_by_lua_block {
  140. local http = require "resty.http"
  141. local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
  142. for i = 1, 2 do
  143. for j = 1, 3 do
  144. local httpc = http.new()
  145. local res, err = httpc:request_uri(uri, {method = "GET"})
  146. if not res or res.body ~= "hello world\n" then
  147. ngx.say(err)
  148. return
  149. end
  150. end
  151. if i < 2 then
  152. ngx.sleep(1.1)
  153. end
  154. end
  155. }
  156. }
  157. --- request
  158. GET /t
  159. --- grep_error_log eval
  160. qr/connect to 127.0.0.1:1053/
  161. --- grep_error_log_out
  162. connect to 127.0.0.1:1053
  163. connect to 127.0.0.1:1053
  164. === TEST 5: cache expire (override ttl)
  165. --- log_level: debug
  166. --- yaml_config
  167. apisix:
  168. node_listen: 1984
  169. dns_resolver_valid: 1
  170. deployment:
  171. role: data_plane
  172. role_data_plane:
  173. config_provider: yaml
  174. --- apisix_yaml
  175. upstreams:
  176. - id: 1
  177. nodes:
  178. ttl.test.local:1980: 1
  179. type: roundrobin
  180. --- config
  181. location /t {
  182. content_by_lua_block {
  183. local http = require "resty.http"
  184. local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
  185. for i = 1, 2 do
  186. for j = 1, 3 do
  187. local httpc = http.new()
  188. local res, err = httpc:request_uri(uri, {method = "GET"})
  189. if not res or res.body ~= "hello world\n" then
  190. ngx.say(err)
  191. return
  192. end
  193. end
  194. if i < 2 then
  195. ngx.sleep(1.1)
  196. end
  197. end
  198. }
  199. }
  200. --- request
  201. GET /t
  202. --- grep_error_log eval
  203. qr/connect to 127.0.0.1:1053/
  204. --- grep_error_log_out
  205. connect to 127.0.0.1:1053
  206. connect to 127.0.0.1:1053