2
0

timeout-upstream.t 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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('info');
  20. worker_connections(256);
  21. no_root_location();
  22. no_shuffle();
  23. run_tests();
  24. __DATA__
  25. === TEST 1: set route(id: 1)
  26. --- config
  27. location /t {
  28. content_by_lua_block {
  29. local t = require("lib.test_admin").test
  30. local code, body = t('/apisix/admin/routes/1',
  31. ngx.HTTP_PUT,
  32. [[{
  33. "methods": ["GET"],
  34. "upstream": {
  35. "nodes": {
  36. "127.0.0.1:1980": 1
  37. },
  38. "type": "roundrobin",
  39. "timeout": {
  40. "connect": 0.5,
  41. "send": 0.5,
  42. "read": 0.5
  43. }
  44. },
  45. "uri": "/mysleep"
  46. }]]
  47. )
  48. if code >= 300 then
  49. ngx.status = code
  50. end
  51. ngx.say(body)
  52. }
  53. }
  54. --- request
  55. GET /t
  56. --- response_body
  57. passed
  58. === TEST 2: hit routes (timeout)
  59. --- request
  60. GET /mysleep?seconds=1
  61. --- error_code: 504
  62. --- response_body eval
  63. qr/504 Gateway Time-out/
  64. --- error_log
  65. timed out) while reading response header from upstream
  66. === TEST 3: set custom timeout for route(overwrite upstream timeout)
  67. --- config
  68. location /t {
  69. content_by_lua_block {
  70. local t = require("lib.test_admin").test
  71. local code, body = t('/apisix/admin/routes/1',
  72. ngx.HTTP_PUT,
  73. [[{
  74. "methods": ["GET"],
  75. "timeout": {
  76. "connect": 0.5,
  77. "send": 0.5,
  78. "read": 0.5
  79. },
  80. "upstream": {
  81. "nodes": {
  82. "127.0.0.1:1980": 1
  83. },
  84. "type": "roundrobin",
  85. "timeout": {
  86. "connect": 2,
  87. "send": 2,
  88. "read": 2
  89. }
  90. },
  91. "uri": "/mysleep"
  92. }]]
  93. )
  94. if code >= 300 then
  95. ngx.status = code
  96. end
  97. ngx.say(body)
  98. }
  99. }
  100. --- request
  101. GET /t
  102. --- response_body
  103. passed
  104. === TEST 4: hit routes (timeout)
  105. --- request
  106. GET /mysleep?seconds=1
  107. --- error_code: 504
  108. --- response_body eval
  109. qr/504 Gateway Time-out/
  110. --- error_log
  111. timed out) while reading response header from upstream
  112. === TEST 5: set route inherit hosts from service
  113. --- config
  114. location /t {
  115. content_by_lua_block {
  116. local t = require("lib.test_admin").test
  117. local scode, sbody = t('/apisix/admin/services/1',
  118. ngx.HTTP_PUT,
  119. [[{
  120. "desc":"test-service",
  121. "hosts": ["foo.com"]
  122. }]]
  123. )
  124. if scode >= 300 then
  125. ngx.status = scode
  126. end
  127. ngx.say(sbody)
  128. local rcode, rbody = t('/apisix/admin/routes/1',
  129. ngx.HTTP_PUT,
  130. [[{
  131. "methods": ["GET"],
  132. "service_id": "1",
  133. "upstream": {
  134. "nodes": {
  135. "127.0.0.1:1980": 1
  136. },
  137. "type": "roundrobin",
  138. "timeout": {
  139. "connect": 0.5,
  140. "send": 0.5,
  141. "read": 0.5
  142. }
  143. },
  144. "uri": "/mysleep"
  145. }]]
  146. )
  147. if rcode >= 300 then
  148. ngx.status = rcode
  149. end
  150. ngx.say(rbody)
  151. }
  152. }
  153. --- request
  154. GET /t
  155. --- response_body
  156. passed
  157. passed
  158. === TEST 6: hit service route (timeout)
  159. --- request
  160. GET /mysleep?seconds=1
  161. --- more_headers
  162. Host: foo.com
  163. --- error_code: 504
  164. --- response_body eval
  165. qr/504 Gateway Time-out/
  166. --- error_log
  167. timed out) while reading response header from upstream