File: balancer-bind.t

package info (click to toggle)
lua-resty-core 0.1.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,176 kB
  • sloc: perl: 143; sh: 59; makefile: 26
file content (109 lines) | stat: -rw-r--r-- 2,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# vim:set ft= ts=4 sw=4 et fdm=marker:
use lib '.';
use t::TestCore::Stream;

repeat_each(2);

plan tests => repeat_each() * (blocks() * 4);

$ENV{TEST_NGINX_LUA_PACKAGE_PATH} = "$t::TestCore::Stream::lua_package_path";

$ENV{TEST_NGINX_UPSTREAM_PORT} ||= get_unused_port 12345;

no_long_string();
run_tests();

__DATA__

=== TEST 1: balancer
--- stream_config
    lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
    upstream backend {
        server 0.0.0.1:1234 down;
        balancer_by_lua_block {
            local b = require "ngx.balancer"
            assert(b.set_current_peer("127.0.0.1", $TEST_NGINX_UPSTREAM_PORT))
        }
    }
    server {
        listen 127.0.0.1:$TEST_NGINX_UPSTREAM_PORT;
        content_by_lua_block {
            ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port)
        }
    }
--- stream_server_config
    proxy_pass backend;
--- request
    GET /t
--- response_body eval
[
qr/127.0.0.1/,
]
--- error_code: 200
--- no_error_log
[error]
[warn]



=== TEST 2: balancer with bind_to_local_addr (addr)
--- stream_config
    lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
    upstream backend {
        server 0.0.0.1:1234 down;
        balancer_by_lua_block {
            local b = require "ngx.balancer"
            assert(b.set_current_peer("127.0.0.1", $TEST_NGINX_UPSTREAM_PORT))
            assert(b.bind_to_local_addr("127.0.0.4"))
        }
    }
    server {
        listen 127.0.0.1:$TEST_NGINX_UPSTREAM_PORT;
        content_by_lua_block {
            ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port)
        }
    }
--- stream_server_config
    proxy_pass backend;
--- request
    GET /t
--- response_body eval
[
qr/127.0.0.4/,
]
--- error_code: 200
--- no_error_log
[error]
[warn]



=== TEST 3: balancer with bind_to_local_addr (addr and port)
--- stream_config
    lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
    upstream backend {
        server 0.0.0.1:1234 down;
        balancer_by_lua_block {
            local b = require "ngx.balancer"
            assert(b.set_current_peer("127.0.0.1", $TEST_NGINX_UPSTREAM_PORT))
            assert(b.bind_to_local_addr("127.0.0.8:23456"))
        }
    }
    server {
        listen 127.0.0.1:$TEST_NGINX_UPSTREAM_PORT;
        content_by_lua_block {
            ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port)
        }
    }
--- stream_server_config
    proxy_pass backend;
--- request
    GET /t
--- response_body eval
[
qr/127.0.0.8/,
]
--- error_code: 200
--- no_error_log
[error]
[warn]