summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFei Hu <feihu@stripe.com>2023-05-09 11:03:22 -0700
committerdormando <dormando@rydia.net>2023-05-09 11:23:36 -0700
commit279eec1f1d8d9be059d693ff367d55f0f33fe2ae (patch)
tree38968505628b3cbc012b953f78ae8317b928352e
parent660054177759e1ece9b86e2ab014dec03004d86d (diff)
downloadmemcached-279eec1f1d8d9be059d693ff367d55f0f33fe2ae.tar.gz
proxy: add more tests around request APIs to proxyunits.t
-rw-r--r--t/proxyunits.lua78
-rw-r--r--t/proxyunits.t65
2 files changed, 123 insertions, 20 deletions
diff --git a/t/proxyunits.lua b/t/proxyunits.lua
index 30bf31f..2bc2ed6 100644
--- a/t/proxyunits.lua
+++ b/t/proxyunits.lua
@@ -130,12 +130,78 @@ function mcp_config_routes(zones)
elseif r:has_flag("O") then
return "HD Oabc\r\n"
end
- return "FAIL"
+ return "NF\r\n"
+ end
+
+ -- Input flags: N10 k c R10
+ -- Output flags: N100 k R100
+ pfx_mg["flagtoken"] = function(r)
+ -- flag_token on non-existing flags: no effect
+ local Ttoken = r:flag_token("T", "T100")
+ local Otoken = r:flag_token("O", nil)
+ local vtoken = r:flag_token("v", "")
+ if vtoken or Otoken or Ttoken then
+ return "ERROR found non-existing flag."
+ end
+
+ -- flag_token to replace: N10 -> N100
+ local found, Ntoken = r:flag_token("N", "N100")
+ if not found or Ntoken ~= "10" then
+ return "ERROR unexpected N token."
+ end
+
+ -- flag_token with nil 2nd arg: equvalent to fetch
+ r:flag_token("k", nil)
+ if not r:has_flag("k") then
+ return "ERROR unexpected k token."
+ end
+
+ -- flag_token with self 2nd arg: no effect
+ r:flag_token("c", "c")
+ if not r:has_flag("c") then
+ return "ERROR unexpected c token 1."
+ end
+
+ -- flag_token with "" 2nd arg: remove
+ r:flag_token("c", "")
+ if r:has_flag("c") then
+ return "ERROR unexpected c token 2."
+ end
+
+ -- repeated flag_token calls: new value is returned.
+ local _, Rtoken = r:flag_token("R", "R100")
+ if Rtoken ~= '10' then
+ return "ERROR unexpected R token 1."
+ end
+ _, Rtoken = r:flag_token("R", "R100")
+ if Rtoken ~= '100' then
+ return "ERROR unexpected R token 2."
+ end
+
+ return "HD\r\n"
+ end
+
+ pfx_ms["request"] = function(r)
+ local key = r:key()
+ local newReq = mcp.request("ms /request/edit 2\r\n", "ab\r\n")
+ return zones.z1(newReq)
+ end
+
+ pfx_mg["request"] = function(r)
+ local key = r:key()
+ if key == "/request/old" then
+ local newReq = mcp.request("mg /request/new c\r\n")
+ return zones.z1(newReq)
+ else
+ local res = zones.z1(r)
+ local newReq = mcp.request("ms /request/a " .. res:vlen() .. "\r\n", res)
+ return zones.z1(newReq)
+ end
end
pfx_get["hasflag"] = function(r)
if r:has_flag("F") then
- return "FAIL"
+ return "ERROR flag found\r\n"
end
return "END\r\n"
end
@@ -150,13 +216,9 @@ function mcp_config_routes(zones)
return zones.z1(r)
else
local token = r:token(2)
- if token == "/token/fetch" then
- return "HD\r\n"
- else
- return "NF\r\n"
- end
+ r:flag_token("P", "P" .. token)
+ return zones.z1(r)
end
- return "FAIL"
end
-- Basic test for routing requests to specific pools.
diff --git a/t/proxyunits.t b/t/proxyunits.t
index 4280969..93c0d1e 100644
--- a/t/proxyunits.t
+++ b/t/proxyunits.t
@@ -594,16 +594,18 @@ check_sanity($ps);
};
subtest 'request:token() fetch' => sub {
- # ps_recv must received HD for a successful fetch call.
+ # be_recv must received the key token in the P flag.
proxy_test(
- ps_send => "ms /token/fetch 2 C123\r\nhi\r\n",
+ ps_send => "ms /token/fetch 2 C123 P\r\nhi\r\n",
+ be_recv => {0 => ["ms /token/fetch 2 C123 P/token/fetch\r\n", "hi\r\n"]},
+ be_send => {0 => ["HD\r\n"]},
ps_recv => ["HD\r\n"],
);
};
# # command() integer
- subtest 'request:has_flag() meta 1' => sub {
+ subtest 'request:has_flag() meta positive 1' => sub {
# ps_recv must receive HD C123 for a successful hash_flag call.
proxy_test(
ps_send => "mg /hasflag/test c\r\n",
@@ -611,7 +613,7 @@ check_sanity($ps);
);
};
- subtest 'request:has_flag() meta 2' => sub {
+ subtest 'request:has_flag() meta positive 2' => sub {
# ps_recv must receive HD Oabc for a successful hash_flag call.
proxy_test(
ps_send => "mg /hasflag/test Oabc T999\r\n",
@@ -619,6 +621,14 @@ check_sanity($ps);
);
};
+ subtest 'request:has_flag() meta negative' => sub {
+ # ps_recv must receive NF when has_flag returns false.
+ proxy_test(
+ ps_send => "mg /hasflag/test T999\r\n",
+ ps_recv => ["NF\r\n"],
+ );
+ };
+
subtest 'request:has_flag() none-meta ' => sub {
# ps_recv must receive END for a successful hash_flag call.
proxy_test(
@@ -627,15 +637,46 @@ check_sanity($ps);
);
};
- # flag_token("F") with no token (bool, nil|token)
- # flag_token("F") with token
- # flag_token("F", "FReplacement")
- # flag_token("F", "") removal
- # flag_token("F", "FReplacement") -> flag_token("F") test repeated fetch
+ subtest 'request:flag_token()' => sub {
+ # be_recv must receive expected flags after a series of flag_token() calls.
+ proxy_test(
+ ps_send => "mg /flagtoken/a N10 k c R10\r\n",
+ ps_recv => ["HD\r\n"],
+ );
+ };
+
- # mcp.request() - has a few modes to test
- # - allows passing in an existing request to clone/edit
- # - passing in value blob
+ subtest 'request edit' => sub {
+ # be_recv must receive the edited request.
+ proxy_test(
+ ps_send => "ms /request/edit 2\r\nhi\r\n",
+ be_recv => {0 => ["ms /request/edit 2\r\n", "ab\r\n"]},
+ be_send => {0 => ["HD\r\n"]},
+ ps_recv => ["HD\r\n"],
+ );
+ };
+
+ subtest 'request new' => sub {
+ # be_recv must receive the new request.
+ proxy_test(
+ ps_send => "mg /request/old\r\n",
+ be_recv => {0 => ["mg /request/new c\r\n"]},
+ be_send => {0 => ["HD C123\r\n"]},
+ ps_recv => ["HD C123\r\n"],
+ );
+ };
+
+ subtest 'request clone response' => sub {
+ # be must receive cloned meta-set from the previous meta-get.
+ my $be = $mbe[0];
+ print $ps "mg /request/clone v\r\n";
+ is(scalar <$be>, "mg /request/clone v\r\n", "get passthrough");
+ print $be "VA 1 v\r\n4\r\n";
+ is(scalar <$be>, "ms /request/a 1\r\n", "received cloned meta-set");
+ is(scalar <$be>, "4\r\n", "received cloned meta-set value");
+ print $be "HD\r\n";
+ is(scalar <$ps>, "HD\r\n", "received HD");
+ };
}
check_sanity($ps);