Skip to content

Commit

Permalink
THREESCALE-10582 e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Feb 4, 2024
1 parent ee07ae5 commit f8b00e9
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gateway/src/resty/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ function _M:set_timeouts(connect_timeout, send_timeout, read_timeout)

-- If one of the values is nil, the default applies:
-- https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md#set_timeouts
ngx.log(ngx.DEBUG, 'setting timeouts (secs), connect_timeout: ', connect_timeout,
' send_timeout: ', send_timeout, ' read_timeout: ', read_timeout)
return ngx_balancer.set_timeouts(connect_timeout, send_timeout, read_timeout)
end

Expand Down
10 changes: 9 additions & 1 deletion gateway/src/resty/resolver/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ function _M.new(opts)

local timeouts = opts.timeouts
if timeouts then
http:set_timeouts(timeouts.connect_timeout, timeouts.send_timeout, timeouts.read_timeout)
ngx.log(ngx.DEBUG, 'setting timeouts (secs), connect_timeout: ', timeouts.connect_timeout,
' send_timeout: ', timeouts.send_timeout, ' read_timeout: ', timeouts.read_timeout)

Check warning on line 18 in gateway/src/resty/resolver/http.lua

View check run for this annotation

Codecov / codecov/patch

gateway/src/resty/resolver/http.lua#L17-L18

Added lines #L17 - L18 were not covered by tests
-- lua-resty-http uses nginx API for lua sockets
-- in milliseconds
-- https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#tcpsocksettimeouts
local connect_timeout = timeouts.connect_timeout and timeouts.connect_timeout * 1000
local send_timeout = timeouts.send_timeout and timeouts.send_timeout * 1000
local read_timeout = timeouts.read_timeout and timeouts.read_timeout * 1000
http:set_timeouts(connect_timeout, send_timeout, read_timeout)

Check warning on line 25 in gateway/src/resty/resolver/http.lua

View check run for this annotation

Codecov / codecov/patch

gateway/src/resty/resolver/http.lua#L22-L25

Added lines #L22 - L25 were not covered by tests
end

http.resolver = resty_resolver:instance()
Expand Down
4 changes: 1 addition & 3 deletions t/apicast-policy-http-proxy.t
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,8 @@ ETag: foobar
--- error_code: 200
--- error_log env
proxy request: CONNECT test-upstream.lvh.me:$TEST_NGINX_RANDOM_PORT HTTP/1.1
--- user_files fixture=tls.pl eval
--- error_log env
using proxy: $TEST_NGINX_HTTPS_PROXY
--- user_files fixture=tls.pl eval
=== TEST 4: using HTTP proxy with Basic Auth
--- configuration
Expand Down
87 changes: 87 additions & 0 deletions t/apicast-policy-upstream-connection.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use lib 't';
use Test::APIcast::Blackbox 'no_plan';

require("http_proxy.pl");

run_tests();

__DATA__
Expand Down Expand Up @@ -59,3 +61,88 @@ GET /
--- error_log
upstream timed out
--- error_code:
=== TEST 2: Set timeouts using HTTPS proxy for backend
In this test we set some timeouts to 1s. To force a read timeout, the upstream
returns part of the response, then waits 3s (more than the timeout defined),
and after that, it returns the rest of the response. Backend is configured with https_proxy
This test uses the "ignore_response" section, because we know that the response
is not going to be complete and that makes the Test::Nginx framework raise an
error. With "ignore_response" that error is ignored.
--- configuration random_port env
{
"services": [
{
"backend_version": 1,
"proxy": {
"api_backend": "https://test-upstream.lvh.me:$TEST_NGINX_RANDOM_PORT",
"proxy_rules": [
{ "pattern": "/test", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
],
"policy_chain": [
{
"name": "apicast.policy.upstream_connection",
"configuration": {
"connect_timeout": 1,
"send_timeout": 1,
"read_timeout": 1
}
},
{
"name": "apicast.policy.http_proxy",
"configuration": {
"https_proxy": "$TEST_NGINX_HTTPS_PROXY"
}
},
{
"name": "apicast.policy.apicast"
}
]
}
}
]
}
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.exit(ngx.OK)
}
}
--- upstream env
server_name test-upstream.lvh.me;
listen $TEST_NGINX_RANDOM_PORT ssl;
ssl_certificate $TEST_NGINX_SERVER_ROOT/html/server.crt;
ssl_certificate_key $TEST_NGINX_SERVER_ROOT/html/server.key;
location /test {
content_by_lua_block {
ngx.say("first part")
ngx.flush(true)
ngx.sleep(3)
ngx.say("yay, second part")
}
access_by_lua_block {
assert = require('luassert')
assert.equal('https', ngx.var.scheme)
assert.equal('$TEST_NGINX_RANDOM_PORT', ngx.var.server_port)
assert.equal('test-upstream.lvh.me', ngx.var.ssl_server_name)
local host = ngx.req.get_headers()["Host"]
local result = string.match(host, "^test%-upstream%.lvh%.me:")
assert.equals(result, "test-upstream.lvh.me:")
}
}
--- request
GET /test?user_key=test3
--- ignore_response
--- more_headers
User-Agent: Test::APIcast::Blackbox
ETag: foobar
--- error_code:
--- error_log env
proxy request: CONNECT test-upstream.lvh.me:$TEST_NGINX_RANDOM_PORT HTTP/1.1
using proxy: $TEST_NGINX_HTTPS_PROXY
proxy_response(): timeout
--- user_files fixture=tls.pl eval

0 comments on commit f8b00e9

Please sign in to comment.