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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
# vim:set ft= ts=4 sw=4 et fdm=marker:
use lib 'lib';
use Test::Nginx::Socket::Lua;
#worker_connections(1014);
#master_process_enabled(1);
#log_level('warn');
#repeat_each(2);
plan tests => repeat_each() * (blocks() * 3 - 1);
#no_diff();
no_long_string();
#master_on();
#workers(2);
run_tests();
__DATA__
=== TEST 1: require test
--- http_config
lua_fake_shm x1 1m;
lua_fake_shm x2 1m;
--- config
location = /test {
content_by_lua_block {
local shm_zones = require("fake_shm_zones")
ngx.say(type(shm_zones))
local x1 = shm_zones.x1
ngx.say(type(x1))
local x2 = shm_zones.x2
ngx.say(type(x1))
}
}
--- request
GET /test
--- response_body
table
table
table
--- no_error_log
[error]
=== TEST 2: index shm_zone
--- http_config
lua_fake_shm x1 1m;
--- config
location = /test {
content_by_lua_block {
local shm_zones = require("fake_shm_zones")
local x1 = shm_zones.x1
ngx.say(type(x1))
}
}
--- request
GET /test
--- response_body
table
--- no_error_log
[error]
=== TEST 3: get_info
--- http_config
lua_fake_shm x1 1m;
--- config
location = /test {
content_by_lua_block {
local shm_zones = require("fake_shm_zones")
local name, size, isinit, isold
local x1 = shm_zones.x1
name, size, isinit, isold = x1:get_info()
ngx.say("name=", name)
ngx.say("size=", size)
ngx.say("isinit=", isinit)
ngx.say("isold=", isold)
}
}
--- request
GET /test
--- response_body
name=x1
size=1048576
isinit=true
isold=false
--- no_error_log
[error]
=== TEST 4: multiply zones
--- http_config
lua_fake_shm x1 1m;
lua_fake_shm x2 2m;
lua_fake_shm x3 3m;
--- config
location = /test {
content_by_lua_block {
local shm_zones = require("fake_shm_zones")
local name, size, isinit, isold
local x1 = shm_zones.x1
local x2 = shm_zones.x2
local x3 = shm_zones.x3
name, size, isinit, isold = x1:get_info()
ngx.say("name=", name)
ngx.say("size=", size)
ngx.say("isinit=", isinit)
ngx.say("isold=", isold)
name, size, isinit, isold = x2:get_info()
ngx.say("name=", name)
ngx.say("size=", size)
ngx.say("isinit=", isinit)
ngx.say("isold=", isold)
name, size, isinit, isold = x3:get_info()
ngx.say("name=", name)
ngx.say("size=", size)
ngx.say("isinit=", isinit)
ngx.say("isold=", isold)
}
}
--- request
GET /test
--- response_body
name=x1
size=1048576
isinit=true
isold=false
name=x2
size=2097152
isinit=true
isold=false
name=x3
size=3145728
isinit=true
isold=false
--- no_error_log
[error]
=== TEST 5: duplicate zones
--- http_config
lua_fake_shm x1 1m;
lua_fake_shm x1 1m;
--- config
location = /test {
content_by_lua_block {
local shm_zones = require("fake_shm_zones")
local x1 = shm_zones.x1
ngx.say("error")
}
}
--- request
GET /test
--- request_body_unlike
error
--- must_die
--- error_log
lua_fake_shm "x1" is already defined as "x1"
--- error_log
[emerg]
|