Skip to content

Commit

Permalink
internal subrctx test
Browse files Browse the repository at this point in the history
should modernize the test file...
  • Loading branch information
dormando committed Jan 14, 2025
1 parent 4252ef4 commit 8371606
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
20 changes: 19 additions & 1 deletion t/proxyinternal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@ function mcp_config_pools()
return true
end

function make_sub()
local fg = mcp.funcgen_new()
local h = fg:new_handle(mcp.internal_backend)
fg:ready({ n = "subint", f = function(rctx)
return function(r)
return rctx:enqueue_and_wait(r, h)
end
end})
return fg
end

function mcp_config_routes(zones)
local fg = mcp.funcgen_new()
local subfg = make_sub()
local h = fg:new_handle(mcp.internal_backend)
local hsub = fg:new_handle(subfg)
fg:ready({ n = "internal", f = function(rctx)
return function(r)
return rctx:enqueue_and_wait(r, h)
local k = r:key()
if string.find(k, "^/sub/") then
return rctx:enqueue_and_wait(r, hsub)
else
return rctx:enqueue_and_wait(r, h)
end
end
end})

Expand Down
20 changes: 20 additions & 0 deletions t/proxyinternal.t
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ note "ascii basic";
# non-multiget get mode.
print $ps "get /b/miss\r\n";
is(scalar <$ps>, "END\r\n", "basic miss");
print $ps "get /sub/miss\r\n";
is(scalar <$ps>, "END\r\n", "basic subrctx miss");

check_version($ps);
}

Expand All @@ -108,10 +111,18 @@ note "ascii basic";
{
print $ps "set /b/foo 0 0 2\r\nhi\r\n";
is(scalar <$ps>, "STORED\r\n", "int set");
print $ps "set /sub/foo 0 0 2\r\nhi\r\n";
is(scalar <$ps>, "STORED\r\n", "int set");

print $ps "get /b/foo\r\n";
is(scalar <$ps>, "VALUE /b/foo 0 2\r\n", "get response");
is(scalar <$ps>, "hi\r\n", "get value");
is(scalar <$ps>, "END\r\n", "get END");

print $ps "get /sub/foo\r\n";
is(scalar <$ps>, "VALUE /sub/foo 0 2\r\n", "get response");
is(scalar <$ps>, "hi\r\n", "get value");
is(scalar <$ps>, "END\r\n", "get END");
check_version($ps);
}

Expand Down Expand Up @@ -149,12 +160,21 @@ subtest 'fetch from extstore' => sub {
my $data = 'x' x 1000;
print $ps "set /b/ext 0 0 1000\r\n$data\r\n";
is(scalar <$ps>, "STORED\r\n", "int set for extstore");

print $ps "set /sub/ext 0 0 1000\r\n$data\r\n";
is(scalar <$ps>, "STORED\r\n", "int set for subrctx extstore");

wait_ext_flush($ps);

print $ps "get /b/ext\r\n";
is(scalar <$ps>, "VALUE /b/ext 0 1000\r\n", "get response from extstore");
is(scalar <$ps>, "$data\r\n", "got data from extstore");
is(scalar <$ps>, "END\r\n", "get END");

print $ps "get /sub/ext\r\n";
is(scalar <$ps>, "VALUE /sub/ext 0 1000\r\n", "get response from subrctx extstore");
is(scalar <$ps>, "$data\r\n", "got data from extstore");
is(scalar <$ps>, "END\r\n", "get END");
};

#diag "flood memory"
Expand Down

0 comments on commit 8371606

Please sign in to comment.