|
| 1 | +# vim:set ft= ts=4 sw=4 et fdm=marker: |
| 2 | + |
| 3 | +use Test::Nginx::Socket::Lua::Stream; |
| 4 | + |
| 5 | +add_block_preprocessor(sub { |
| 6 | + my $block = shift; |
| 7 | + |
| 8 | + my $stream_config = $block->stream_config || ''; |
| 9 | + |
| 10 | + $stream_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("stream_config", $stream_config); |
| 39 | + |
| 40 | + if (!defined $block->stream_server_config) { |
| 41 | + my $stream_config = <<_EOC_; |
| 42 | + content_by_lua_block { |
| 43 | + ngx.say("ok") |
| 44 | + } |
| 45 | +_EOC_ |
| 46 | + |
| 47 | + $block->set_value("stream_server_config", $stream_config); |
| 48 | + } |
| 49 | + |
| 50 | + if (!defined $block->no_error_log) { |
| 51 | + $block->set_value("no_error_log", "[error]"); |
| 52 | + } |
| 53 | +}); |
| 54 | + |
| 55 | +plan tests => repeat_each() * (blocks() * 2 + 1); |
| 56 | + |
| 57 | +no_long_string(); |
| 58 | +run_tests(); |
| 59 | + |
| 60 | +__DATA__ |
| 61 | +
|
| 62 | +=== TEST 1: lua_sa_restart default - sets SA_RESTART in init_worker_by_lua* |
| 63 | +--- stream_config |
| 64 | + init_worker_by_lua_block { |
| 65 | + test_sa_restart() |
| 66 | + } |
| 67 | +
|
| 68 | +
|
| 69 | +
|
| 70 | +=== TEST 2: lua_sa_restart off - does not set SA_RESTART |
| 71 | +We must specify the lua_sa_restart directive in the http block as well, since |
| 72 | +otherwise, ngx_lua's own default of lua_sa_restart is 'on', and ngx_lua |
| 73 | +re-enables the SA_RESTART flag. |
| 74 | +--- http_config |
| 75 | + lua_sa_restart off; |
| 76 | +--- stream_config |
| 77 | + lua_sa_restart off; |
| 78 | +
|
| 79 | + init_worker_by_lua_block { |
| 80 | + test_sa_restart() |
| 81 | + } |
| 82 | +--- no_error_log |
| 83 | +[crit] |
| 84 | +--- error_log |
| 85 | +Interrupted system call |
| 86 | +
|
| 87 | +
|
| 88 | +
|
| 89 | +=== TEST 3: lua_sa_restart on (default) - sets SA_RESTART if no init_worker_by_lua* phase is defined |
| 90 | +--- stream_server_config |
| 91 | + content_by_lua_block { |
| 92 | + test_sa_restart() |
| 93 | + } |
| 94 | +
|
| 95 | +
|
| 96 | +
|
| 97 | +=== TEST 4: lua_sa_restart on (default) - SA_RESTART is effective in content_by_lua* |
| 98 | +--- stream_server_config |
| 99 | + content_by_lua_block { |
| 100 | + test_sa_restart() |
| 101 | + } |
| 102 | +
|
| 103 | +
|
| 104 | +
|
| 105 | +=== TEST 5: lua_sa_restart on (default) - SA_RESTART is effective in log_by_lua* |
| 106 | +--- stream_server_config |
| 107 | + content_by_lua_block { |
| 108 | + ngx.say("ok") |
| 109 | + } |
| 110 | +
|
| 111 | + log_by_lua_block { |
| 112 | + test_sa_restart() |
| 113 | + } |
| 114 | +
|
| 115 | +
|
| 116 | +
|
| 117 | +=== TEST 6: lua_sa_restart on (default) - SA_RESTART is effective in timer phase |
| 118 | +--- stream_server_config |
| 119 | + content_by_lua_block { |
| 120 | + ngx.say("ok") |
| 121 | + } |
| 122 | +
|
| 123 | + log_by_lua_block { |
| 124 | + ngx.timer.at(0, test_sa_restart) |
| 125 | + } |
0 commit comments