Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: added new test cases for multiple worker. #33

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions t/multiple-worker.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use Test::Nginx::Socket::Lua 'no_plan';

use Cwd qw(cwd);
my $pwd = cwd();

#no_diff();
repeat_each(1);
no_long_string();
master_on();
workers(4);

our $HttpConfig = <<_EOC_;
lua_socket_log_errors off;
lua_package_path "$pwd/lib/?.lua;;";
_EOC_

run_tests();

__DATA__

=== TEST 1: worker.events posting and handling events, broadcast
--- http_config eval
"$::HttpConfig"
. q{
lua_shared_dict worker_events 1m;
init_worker_by_lua_block {
ngx.shared.worker_events:flush_all()

local we = require "resty.worker.events"
we.register(function(data, event, source, pid)
ngx.log(ngx.DEBUG, "worker-events: handler event; ",
"source=",source, ", event=",event, ", pid=", pid,
", data=", data)
end)

local ok, err = we.configure{
shm = "worker_events",
interval = 0.001
}
if not ok then
ngx.log(ngx.ERR, "failed to configure worker events: ", err)
return
end
}
}
--- config
location = /t {
access_log off;
content_by_lua_block {
ngx.sleep(0.5)
local we = require "resty.worker.events"
we.post("content_by_lua","request1","01234567890")
ngx.sleep(0.5)
ngx.say("hello world")
}
}

--- request
GET /t

--- response_body
hello world
--- no_error_log
[error]
[alert]
[warn]
dropping event: waiting for event data timed out
--- grep_error_log eval: qr/worker-events: handler event.*, data=01234567890/
--- grep_error_log_out eval
qr/^worker-events: handler event; source=content_by_lua, event=request1, pid=\d+, data=01234567890
worker-events: handler event; source=content_by_lua, event=request1, pid=\d+, data=01234567890
worker-events: handler event; source=content_by_lua, event=request1, pid=\d+, data=01234567890/
--- wait: 1



=== TEST 2: worker.events posting and handling events, broadcast local
--- http_config eval
"$::HttpConfig"
. q{
lua_shared_dict worker_events 1m;
init_worker_by_lua_block {
ngx.shared.worker_events:flush_all()

local we = require "resty.worker.events"
we.register(function(data, event, source, pid)
ngx.log(ngx.DEBUG, "worker-events: handler event; ",
"source=",source, ", event=",event, ", pid=", pid,
", data=", data)
end)

local ok, err = we.configure{
shm = "worker_events",
interval = 0.001
}
if not ok then
ngx.log(ngx.ERR, "failed to configure worker events: ", err)
return
end
}
}
--- config
location = /t {
access_log off;
content_by_lua_block {
ngx.sleep(0.5)
local we = require "resty.worker.events"
we.post_local("content_by_lua","request1","01234567890")
ngx.sleep(0.5)
ngx.say("hello world")
}
}

--- request
GET /t

--- response_body
hello world
--- no_error_log
[error]
[alert]
[warn]
dropping event: waiting for event data timed out
--- grep_error_log eval: qr/worker-events: handler event.*, data=01234567890/
--- grep_error_log_out eval
qr/^worker-events: handler event; source=content_by_lua, event=request1, pid=nil, data=01234567890$/
--- wait: 1