From e9cbf39d509bfc091e08908ff9528d6b902a2687 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 23 Oct 2023 18:15:49 +0200 Subject: [PATCH 1/2] balancer.t conversion to blackbox --- t/balancer.t | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/t/balancer.t b/t/balancer.t index 803632ef7..4c968940a 100644 --- a/t/balancer.t +++ b/t/balancer.t @@ -1,27 +1,35 @@ use lib 't'; -use Test::APIcast 'no_plan'; +use Test::APIcast::Blackbox 'no_plan'; -$ENV{TEST_NGINX_HTTP_CONFIG} = "$Test::APIcast::path/http.d/*.conf"; -$ENV{RESOLVER} = '127.0.1.1:5353'; - -env_to_nginx( - 'RESOLVER' -); -master_on(); +repeat_each(1); run_tests(); __DATA__ === TEST 1: round robin does not leak memory Balancing different hosts does not leak memory. ---- http_config - lua_package_path "$TEST_NGINX_LUA_PATH"; - init_by_lua_block { - require('resty.balancer.round_robin').cache_size = 1 +--- configuration + { + "services": [ + { + "proxy": { + "policy_chain": [ + { "name": "apicast.policy.upstream", + "configuration": + { + "rules": [ { "regex": "/", "http_method": "GET", + "url": "http://test:$TEST_NGINX_SERVER_PORT" } ] + } + } + ] + } + } + ] } ---- config +--- upstream location = /t { content_by_lua_block { + require('resty.balancer.round_robin').cache_size = 1 local round_robin = require('resty.balancer.round_robin') local balancer = round_robin.new() From 966e6b2e76d1ccaea39a82db2875db7543293364 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Wed, 25 Oct 2023 17:40:42 +0200 Subject: [PATCH 2/2] use "api_backend" with authentication --- t/balancer.t | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/t/balancer.t b/t/balancer.t index 4c968940a..27a394dc0 100644 --- a/t/balancer.t +++ b/t/balancer.t @@ -1,7 +1,6 @@ use lib 't'; use Test::APIcast::Blackbox 'no_plan'; -repeat_each(1); run_tests(); __DATA__ @@ -9,22 +8,26 @@ __DATA__ === TEST 1: round robin does not leak memory Balancing different hosts does not leak memory. --- configuration - { - "services": [ - { - "proxy": { - "policy_chain": [ - { "name": "apicast.policy.upstream", - "configuration": - { - "rules": [ { "regex": "/", "http_method": "GET", - "url": "http://test:$TEST_NGINX_SERVER_PORT" } ] - } - } - ] +{ + "services": [ + { + "id": 42, + "backend_version": 1, + "backend_authentication_type": "service_token", + "backend_authentication_value": "token-value", + "proxy": { + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ { "pattern" : "/", "http_method" : "GET", + "metric_system_name" : "hits", "delta" : 2 } ] } - } - ] + } + ] +} +--- backend + location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } } --- upstream location = /t { @@ -40,6 +43,6 @@ Balancing different hosts does not leak memory. } } --- pipelined_requests eval -[ "GET /t", "GET /t" ] +[ "GET /t?user_key=value", "GET /t?user_key=value" ] --- response_body eval [ "1", "1" ]