Skip to content

How to run test case?

Xiaochen Wang edited this page Oct 22, 2021 · 10 revisions

NOTE

This is an informal wiki page, just used to record the test methods of the developer Xiaochen. However, this page may help those who want to redevelop and test this project.

Following test environment:

windows 10
 -> WSL 1.0
   -> ubuntu 20.04 From Microsoft Store
     -> nginx

ENV for ubuntu

configure error:

./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using —without–http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using —with–pcre=...

then:

$ sudo apt-get install libpcre3-dev
  • for libluajit and lua-nginx-module
$ sudo apt install libluajit-5.1-dev
  • for openssl devel package
$ sudo apt-get install libssl-dev
  • My private configure & make options:
$ cat genmake.sh
# for ubuntu libluajit-5.1-dev package
export LUAJIT_LIB=/usr/lib/x86_64-linux-gnu/
export LUAJIT_INC=/usr/include/luajit-2.1/
# configure option
./configure --add-module=../ngx_http_proxy_connect_module/ --add-module=../lua-nginx-module/
# compile
make -j

$ sh genmake.sh

ENV for nginx test

WINDOWS-V0HQ9PG pc $ ls
nginx-1.21.0    nginx-1.21.0.tar.gz     ngx_http_proxy_connect_module
^-- nginx source directory

WINDOWS-V0HQ9PG pc $ git clone https://github.com/nginx/nginx-tests
Cloning into 'nginx-tests'...
remote: Enumerating objects: 7543, done.
remote: Counting objects: 100% (620/620), done.
remote: Compressing objects: 100% (418/418), done.
remote: Total 7543 (delta 353), reused 389 (delta 189), pack-reused 6923
Receiving objects: 100% (7543/7543), 3.90 MiB | 4.27 MiB/s, done.
Resolving deltas: 100% (5034/5034), done.
  • modify some path variables of runtest.sh
WINDOWS-V0HQ9PG pc $ pwd
/home/xiaochen/pc
WINDOWS-V0HQ9PG pc $ vim ngx_http_proxy_connect_module/t/runtest.sh      #<<< modify runtest.sh
WINDOWS-V0HQ9PG pc $ cat  ngx_http_proxy_connect_module/t/runtest.sh
# get it from https://github.com/nginx/nginx-tests
nginx_tests_lib_path=/home/xiaochen/pc/nginx-tests/lib

# compiled nginx binary
nginx_binary=/home/xiaochen/pc/nginx-1.21.0/objs/nginx

# path of test cases
proxy_connect_test_cases=/home/xiaochen/pc/ngx_http_proxy_connect_module/t

TEST_NGINX_UNSAFE=yes \
TEST_NGINX_BINARY=$nginx_binary \
prove -v -I $nginx_tests_lib_path  $proxy_connect_test_cases

  • running test case failed and install some PERL test lib
ERROR:
...Can't locate Net/DNS/Nameserver.pm in @INC (you may need to install the Net::DNS::Nameserver module) ...

WINDOWS-V0HQ9PG pc $  sudo perl -MCPAN -e "install Net::DNS::Nameserver"
  • run test case

WINDOWS-V0HQ9PG pc $ sh ngx_http_proxy_connect_module/t/runtest.sh
/home/xiaochen/pc/ngx_http_proxy_connect_module/t/http_proxy_connect.t ....................
+ test_enable_rewrite_phase: 1
+ DNS server: try to bind server port: 18085
+ DNS server: daemon pid: 10854
+ DNS server: working
ok 1 - 200 Connection Established
ok 2 - 200 Connection Established server name
ok 3 - 200 Connection Established server name
ok 4 - 200 Connection Established server name
ok 5 - 200 Connection Established not allowed port
ok 6 - Get method: proxy_pass
ok 7 - Get method: return 200
ok 8 - forbid CONNECT request without proxy_connect command enabled
ok 9 - proxy_remote_address supports dynamic domain resovling
ok 10 - set remote address
ok 11 - set local address and remote address
ok 12 - $connect_host, $connect_port, $connect_addr
ok 13 - dns resolver fail
ok 14 - skip proxy connect module without rewrite phase enabled
ok 15 - skip proxy connect module without rewrite phase enabled: if/return
ok 16 - 200 for default root directive without location {}
ok 17 - 404 for default root directive without location {}
ok 18 - nothing changed with CONNECT response
ok 19 - get default CONNECT response
ok 20 - added header "Foo: bar" to CONNECT response
ok 21 - change CONNECT response status
ok 22 - added header "Foo: bar" to CONNECT response
+ DNS server: stop
1..22
        (in cleanup)    (in cleanup)  at /usr/share/perl/5.30/Test2/API.pm line 174 during global destruction.
ok
/home/xiaochen/pc/ngx_http_proxy_connect_module/t/http_proxy_connect_lua.t ................
1..0 # SKIP no lua available
skipped: no lua available
/home/xiaochen/pc/ngx_http_proxy_connect_module/t/http_proxy_connect_resolve_variables.t ..
+ test_enable_rewrite_phase: 1
+ DNS server: try to bind server port: 18085
+ DNS server: daemon pid: 10873
+ DNS server: working
ok 1 - connect timed out log: get $var & status=504 # TODO # This case will pass, if connecting 8.8.8.8 timed out.
ok 2 - connect timed out error log # TODO # This case will pass, if connecting 8.8.8.8 timed out.
ok 3 - For GET request, both $proxy_connect_resolve_time & $proxy_connect_connect_time are empty string
ok 4 - For CONNECT request, test both $proxy_connect_resolve_time & $proxy_connect_connect_time
ok 5 - For CONNECT request, test both $proxy_connect_resolve_time & $proxy_connect_connect_time
ok 6 - test error.log for 502 respsone
+ DNS server: stop
1..6
        (in cleanup)    (in cleanup)  at /usr/share/perl/5.30/Test2/API.pm line 174 during global destruction.
ok
/home/xiaochen/pc/ngx_http_proxy_connect_module/t/http_proxy_connect_timeout.t ............
+ test_enable_rewrite_phase: 1
+ DNS server: try to bind server port: 18085
+ DNS server: daemon pid: 10880
+ DNS server: working
ok 1 - connect timed out: set $var # TODO # This case will pass, if connecting 8.8.8.8 timed out.
ok 2 - connect timed out log: get $var & status=504 # TODO # This case will pass, if connecting 8.8.8.8 timed out.
ok 3 - connect timed out error log # TODO # This case will pass, if connecting 8.8.8.8 timed out.
ok 4 - connect timed out log: get $var
ok 5 - connect/send/read timed out log: get $var
+ DNS server: stop
1..5
        (in cleanup)    (in cleanup)  at /usr/share/perl/5.30/Test2/API.pm line 174 during global destruction.
ok
All tests successful.

Test Summary Report
-------------------
/home/xiaochen/pc/ngx_http_proxy_connect_module/t/http_proxy_connect_resolve_variables.t (Wstat: 0 Tests: 6 Failed: 0)
  TODO passed:   1-2
/home/xiaochen/pc/ngx_http_proxy_connect_module/t/http_proxy_connect_timeout.t          (Wstat: 0 Tests: 5 Failed: 0)
  TODO passed:   1-3
Files=4, Tests=33,  4 wallclock secs ( 0.05 usr  0.11 sys +  0.51 cusr  2.14 csys =  2.81 CPU)

some errors for running test case and how to resolve

  • no resty.core found

It's hard to install lua-nginx-module with officiall nginx now(2021/10/22), we should install https://github.com/openresty/lua-resty-core and https://github.com/openresty/lua-resty-lrucache, and then fix its path for lua-nginx-module. I dont find good way to fix the path problem, I installed (make install) the lua-resty-core and lua-resty-lrucache, then move them from default path to the right path of error log manually.

Error log is as following:

$ sh ngx_http_proxy_connect_module/t/runtest.sh
/home/xiaochen/work/ngx_http_proxy_connect_module/t/http_proxy_connect.t .................... nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
        no field package.preload['resty.core']
        no file './resty/core.lua'
        ...
        no file '/usr/local/lib/lua/5.1/loadall.so') in /tmp/nginx-test-FJtLWzxKwP/nginx.conf:91