|
| 1 | +# vim:set ft= ts=4 sw=4 et fdm=marker: |
| 2 | + |
| 3 | +use Test::Nginx::Socket::Lua; |
| 4 | + |
| 5 | +add_block_preprocessor(sub { |
| 6 | + my $block = shift; |
| 7 | + |
| 8 | + my $http_config = $block->http_config || ''; |
| 9 | + |
| 10 | + $http_config .= <<_EOC_; |
| 11 | + init_by_lua_block { |
| 12 | + function test_sa_restart() |
| 13 | + local signals = { |
| 14 | + "HUP", |
| 15 | + --"INFO", |
| 16 | + --"XCPU", |
| 17 | + --"USR1", |
| 18 | + --"USR2", |
| 19 | + "ALRM", |
| 20 | + --"INT", |
| 21 | + "IO", |
| 22 | + "CHLD", |
| 23 | + "WINCH", |
| 24 | + } |
| 25 | +
|
| 26 | + for _, signame in ipairs(signals) do |
| 27 | + local cmd = string.format("kill -s %s %d && sleep 0.01", |
| 28 | + signame, ngx.worker.pid()) |
| 29 | + local err = select(2, io.popen(cmd):read("*a")) |
| 30 | + if err then |
| 31 | + error("SIG" .. signame .. " caused: " .. err) |
| 32 | + end |
| 33 | + end |
| 34 | + end |
| 35 | + } |
| 36 | +_EOC_ |
| 37 | + |
| 38 | + $block->set_value("http_config", $http_config); |
| 39 | + |
| 40 | + if (!defined $block->config) { |
| 41 | + my $config = <<_EOC_; |
| 42 | + location /t { |
| 43 | + echo ok; |
| 44 | + } |
| 45 | +_EOC_ |
| 46 | + |
| 47 | + $block->set_value("config", $config); |
| 48 | + } |
| 49 | + |
| 50 | + if (!defined $block->request) { |
| 51 | + $block->set_value("request", "GET /t"); |
| 52 | + } |
| 53 | + |
| 54 | + if (!defined $block->response_body) { |
| 55 | + $block->set_value("ignore_response_body"); |
| 56 | + } |
| 57 | + |
| 58 | + if (!defined $block->no_error_log) { |
| 59 | + $block->set_value("no_error_log", "[error]"); |
| 60 | + } |
| 61 | +}); |
| 62 | + |
| 63 | +plan tests => repeat_each() * (blocks() * 2 + 1); |
| 64 | + |
| 65 | +no_long_string(); |
| 66 | +run_tests(); |
| 67 | + |
| 68 | +__DATA__ |
| 69 | +
|
| 70 | +=== TEST 1: lua_sa_restart default - sets SA_RESTART in init_worker_by_lua* |
| 71 | +--- http_config |
| 72 | + init_worker_by_lua_block { |
| 73 | + test_sa_restart() |
| 74 | + } |
| 75 | +
|
| 76 | +
|
| 77 | +
|
| 78 | +=== TEST 2: lua_sa_restart off - does not set SA_RESTART |
| 79 | +--- http_config |
| 80 | + lua_sa_restart off; |
| 81 | +
|
| 82 | + init_worker_by_lua_block { |
| 83 | + test_sa_restart() |
| 84 | + } |
| 85 | +--- no_error_log |
| 86 | +[crit] |
| 87 | +--- error_log |
| 88 | +Interrupted system call |
| 89 | +
|
| 90 | +
|
| 91 | +
|
| 92 | +=== TEST 3: lua_sa_restart on (default) - sets SA_RESTART if no init_worker_by_lua* phase is defined |
| 93 | +--- config |
| 94 | + location /t { |
| 95 | + content_by_lua_block { |
| 96 | + test_sa_restart() |
| 97 | + } |
| 98 | + } |
| 99 | +
|
| 100 | +
|
| 101 | +
|
| 102 | +=== TEST 4: lua_sa_restart on (default) - SA_RESTART is effective in rewrite_by_lua* |
| 103 | +--- config |
| 104 | + location /t { |
| 105 | + rewrite_by_lua_block { |
| 106 | + test_sa_restart() |
| 107 | + } |
| 108 | +
|
| 109 | + echo ok; |
| 110 | + } |
| 111 | +
|
| 112 | +
|
| 113 | +
|
| 114 | +=== TEST 5: lua_sa_restart on (default) - SA_RESTART is effective in access_by_lua* |
| 115 | +--- config |
| 116 | + location /t { |
| 117 | + access_by_lua_block { |
| 118 | + test_sa_restart() |
| 119 | + } |
| 120 | +
|
| 121 | + echo ok; |
| 122 | + } |
| 123 | +
|
| 124 | +
|
| 125 | +
|
| 126 | +=== TEST 6: lua_sa_restart on (default) - SA_RESTART is effective in content_by_lua* |
| 127 | +--- config |
| 128 | + location /t { |
| 129 | + content_by_lua_block { |
| 130 | + test_sa_restart() |
| 131 | + } |
| 132 | + } |
| 133 | +
|
| 134 | +
|
| 135 | +
|
| 136 | +=== TEST 7: lua_sa_restart on (default) - SA_RESTART is effective in header_filter_by_lua* |
| 137 | +--- config |
| 138 | + location /t { |
| 139 | + echo ok; |
| 140 | +
|
| 141 | + header_filter_by_lua_block { |
| 142 | + test_sa_restart() |
| 143 | + } |
| 144 | + } |
| 145 | +
|
| 146 | +
|
| 147 | +
|
| 148 | +=== TEST 8: lua_sa_restart on (default) - SA_RESTART is effective in body_filter_by_lua* |
| 149 | +--- config |
| 150 | + location /t { |
| 151 | + echo ok; |
| 152 | +
|
| 153 | + body_filter_by_lua_block { |
| 154 | + test_sa_restart() |
| 155 | + } |
| 156 | + } |
| 157 | +
|
| 158 | +
|
| 159 | +
|
| 160 | +=== TEST 9: lua_sa_restart on (default) - SA_RESTART is effective in log_by_lua* |
| 161 | +--- config |
| 162 | + location /t { |
| 163 | + echo ok; |
| 164 | +
|
| 165 | + log_by_lua_block { |
| 166 | + test_sa_restart() |
| 167 | + } |
| 168 | + } |
| 169 | +
|
| 170 | +
|
| 171 | +
|
| 172 | +=== TEST 10: lua_sa_restart on (default) - SA_RESTART is effective in timer phase |
| 173 | +--- config |
| 174 | + location /t { |
| 175 | + echo ok; |
| 176 | +
|
| 177 | + log_by_lua_block { |
| 178 | + ngx.timer.at(0, test_sa_restart) |
| 179 | + } |
| 180 | + } |
0 commit comments