Hi,
I am trying to find out code coverage of my tests written using test-nginx framework. But ever since I added luacov to init_by_lua_block I started getting "client socket timed out" error for all my tests.
Here's a sample error from a test run
TEST 2.2: anonymizePIIFromURL Should return un anonymised url if AP feature flag is off - WARNING: killing the child process 104074 with force... at lib/Test/Nginx/Util.pm line 591.
t/Unit/website/utils.t .. 29/21
# Failed test 'ERROR: client socket timed out - TEST 2.2: anonymizePIIFromURL Should return un anonymised url if AP feature flag is off
# '
# at /var/www/dev/test/blib/lib/Test/Nginx/Socket.pm line 1972.
# Failed test 'TEST 2.2: anonymizePIIFromURL Should return un anonymised url if AP feature flag is off - status code ok'
# at /var/www/dev/test/blib/lib/Test/Nginx/Socket.pm line 939.
# got: ''
# expected: '200'
# Failed test 'TEST 2.2: anonymizePIIFromURL Should return un anonymised url if AP feature flag is off - response_body - response is expected (repeated req 0, req 0)'
# at /var/www/dev/test/blib/lib/Test/Nginx/Socket.pm line 1504.
# got: ""
# length: 0
# expected: "["http:\/\/abc.com\/?e=123@gmail.com"]\x{0a}"
# length: 39
# strings begin to differ at char 1 (line 1 column 1)
END - WARNING: killing the child process 104090 with force... at lib/Test/Nginx/Util.pm line 591.
This is exactly how I've written the test -
=== TEST 2.2: anonymizePIIFromURL Should return un anonymised url if AP feature flag is off
--- http_config
lua_package_path 't/Integration/utils/?.lua;/var/www/dev/lua/?.lua;/var/www/dev/lua/on-page/?.lua;/var/www/dev/libraries/?.lua;;';
lua_package_cpath '../lua/?.so;;';
$TEST_NGINX_COMMON_CONF
--- config
location = /utils {
rewrite_by_lua_block {
local mysqlTestUtils = require "mysql_test_utils";
local accountId, experimentId = 101010, 1;
local accSettings = [[ {"fe":{"AP":0}, "c":{"d":1}} ]]
mysqlTestUtils.cleanUpAccountVisitorSettings(accountId)
mysqlTestUtils.addAccountVisitorSetting(accountId, accSettings)
}
content_by_lua_block {
local web_utils = require "website.utils"
local cjson = require "cjson"
ngx.say(cjson.encode(web_utils.anonymizePIIFromURL(101010, {[1] = "http://abc.com/?e=123@gmail.com"})))
}
}
--- request
GET /utils
--- response_body
["http:\/\/abc.com\/?e=123@gmail.com"]
This is how I've exported the TEST_NGINX_COMMON_CONF variable
read -d '' TEST_NGINX_COMMON_CONF << EOF
lua_shared_dict ACCOUNTSETTINGS 50m;
lua_shared_dict CD_PII 50m;
lua_shared_dict QP_PII 50m;
init_by_lua_block {
runner = require 'luacov.runner'
runner.tick = true
runner.init({savestepsize = 100})
jit.off()
}
EOF
export TEST_NGINX_COMMON_CONF=${TEST_NGINX_COMMON_CONF}
Can someone please suggest a solution to following -
- fixing this timeout issue
- A better way of sharing config across multiple testcases