Skip to content

Commit

Permalink
extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
dormando committed Apr 5, 2024
1 parent 7a2406b commit 8c32405
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
24 changes: 24 additions & 0 deletions t/proxyrctxtimeout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ function wait_more(p)
return fgen
end

function wait_double(p)
local fgen = mcp.funcgen_new()
local near = fgen:new_handle(p.z1)

fgen:ready({ n = "wait_double", f = function(rctx)
return function(r)
rctx:enqueue(r, near)
-- timeout via sleep twice, then continue to function.
local nres, timeout = rctx:wait_handle(near, 0.1)
nres, timeout = rctx:wait_handle(near, 0.1)

-- wait on the same handle twice.
if timeout then
local xres = rctx:wait_handle(near)
return xres
else
return "SERVER_ERROR no timeout\r\n"
end
end
end})
return fgen
end

function rctx_sleep(p)
local fgen = mcp.funcgen_new()
local near = fgen:new_handle(p.z1)
Expand All @@ -143,6 +166,7 @@ function mcp_config_routes(p)
["enqueue_timeout"] = enqueue_timeout(p),
["handle_timeout"] = wait_handle_timeout(p),
["wait_more"] = wait_more(p),
["wait_double"] = wait_double(p),
["sleep"] = rctx_sleep(p),
}

Expand Down
11 changes: 11 additions & 0 deletions t/proxyrctxtimeout.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,15 @@ subtest 'wait handle no timeout' => sub {
$t->clear();
};

subtest 'wait double' => sub {
$t->c_send("mg wait_double/foo t\r\n");
$t->be_recv_c(0, "near got request");
# Let it internally time out.
sleep 0.75;
pass("short sleep");
$t->be_send(0, "HD t98\r\n");
$t->c_recv_be();
$t->clear();
};

done_testing();

0 comments on commit 8c32405

Please sign in to comment.