This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 8.1.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 0a2a2862bd94ef5a53d0d82c57acc08f49080137 Author: Brian Olsen <[email protected]> AuthorDate: Wed Nov 13 22:07:38 2019 +0000 Add autest for cache_range_request, add xdebug x-parentselection-key (cherry picked from commit e02c55fb44c497137e60ac5cd14ab30da683be92) --- .../cache_range_requests.test.py | 344 +++++++++++++++++++++ .../cache_range_requests/gold/404.stdout.gold | 8 + .../cache_range_requests/gold/frange.stderr.gold | 1 + .../cache_range_requests/gold/frange.stdout.gold | 11 + .../cache_range_requests/gold/full.stderr.gold | 1 + .../cache_range_requests/gold/full.stdout.gold | 9 + .../cache_range_requests/gold/inner.stderr.gold | 1 + .../cache_range_requests/gold/inner.stdout.gold | 11 + .../cache_range_requests/gold/last.stderr.gold | 1 + .../cache_range_requests/gold/last.stdout.gold | 11 + .../cache_range_requests/gold/pselect.stdout.gold | 11 + .../gold/pselect_none.stdout.gold | 10 + 12 files changed, 419 insertions(+) diff --git a/tests/gold_tests/pluginTest/cache_range_requests/cache_range_requests.test.py b/tests/gold_tests/pluginTest/cache_range_requests/cache_range_requests.test.py new file mode 100644 index 0000000..77fd29e --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/cache_range_requests.test.py @@ -0,0 +1,344 @@ +''' +''' +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +Test.Summary = ''' +Basic cache_range_requests plugin test +''' + +## Test description: +# Preload the cache with the entire asset to be range requested. +# Reload remap rule with cache_range_requests plugin +# Request content through the cache_range_requests plugin + +Test.SkipUnless( + Condition.PluginExists('cache_range_requests.so'), + Condition.PluginExists('xdebug.so'), +) +Test.ContinueOnFail = False +Test.testName = "cache_range_requests" + +# Define and configure ATS +ts = Test.MakeATSProcess("ts", command="traffic_server") + +# Define and configure origin server +server = Test.MakeOriginServer("server", lookup_key="{%uuid}") + +# default root +req_chk = {"headers": + "GET / HTTP/1.1\r\n" + + "Host: www.example.com\r\n" + + "uuid: none\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": "" +} + +res_chk = {"headers": + "HTTP/1.1 200 OK\r\n" + + "Connection: close\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": "" +} + +server.addResponse("sessionlog.json", req_chk, res_chk) + +body = "lets go surfin now" + +req_full = {"headers": + "GET /path HTTP/1.1\r\n" + + "Host: www.example.com\r\n" + + "Accept: */*\r\n" + + "uuid: full\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": "" +} + +res_full = {"headers": + "HTTP/1.1 200 OK\r\n" + + "Cache-Control: max-age=500\r\n" + + "Connection: close\r\n" + + 'Etag: "772102f4-56f4bc1e6d417"\r\n' + + "Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": body +} + +server.addResponse("sessionlog.json", req_full, res_full) + +block_bytes = 7 +bodylen = len(body) + +inner_str = "7-15" + +req_inner = {"headers": + "GET /path HTTP/1.1\r\n" + + "Host: www.example.com\r\n" + + "Accept: */*\r\n" + + "Range: bytes={}\r\n".format(inner_str) + + "uuid: inner\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": "" +} + +res_inner = {"headers": + "HTTP/1.1 206 Partial Content\r\n" + + "Accept-Ranges: bytes\r\n" + + "Cache-Control: max-age=500\r\n" + + "Content-Range: bytes {0}/{1}\r\n".format(inner_str, bodylen) + + "Connection: close\r\n" + + 'Etag: "772102f4-56f4bc1e6d417"\r\n' + + "Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": body[7:15] +} + +server.addResponse("sessionlog.json", req_inner, res_inner) + +frange_str = "0-" + +req_frange = {"headers": + "GET /path HTTP/1.1\r\n" + + "Host: www.example.com\r\n" + + "Accept: */*\r\n" + + "Range: bytes={}\r\n".format(frange_str) + + "uuid: frange\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": "" +} + +res_frange = {"headers": + "HTTP/1.1 206 Partial Content\r\n" + + "Accept-Ranges: bytes\r\n" + + "Cache-Control: max-age=500\r\n" + + "Content-Range: bytes 0-{0}/{0}\r\n".format(bodylen) + + "Connection: close\r\n" + + 'Etag: "772102f4-56f4bc1e6d417"\r\n' + + "Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": body +} + +server.addResponse("sessionlog.json", req_frange, res_frange) + +last_str = "-5" + +req_last = {"headers": + "GET /path HTTP/1.1\r\n" + + "Host: www.example.com\r\n" + + "Accept: */*\r\n" + + "Range: bytes={}\r\n".format(last_str) + + "uuid: last\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": "" +} + +res_last = {"headers": + "HTTP/1.1 206 Partial Content\r\n" + + "Accept-Ranges: bytes\r\n" + + "Cache-Control: max-age=200\r\n" + + "Content-Range: bytes {0}-{1}/{1}\r\n".format(bodylen - 5, bodylen) + + "Connection: close\r\n" + + 'Etag: "772102f4-56f4bc1e6d417"\r\n' + + "Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": body[-5:] +} + +server.addResponse("sessionlog.json", req_last, res_last) + +pselect_str = "1-10" + +req_pselect = {"headers": + "GET /path HTTP/1.1\r\n" + + "Host: parentselect\r\n" + + "Accept: */*\r\n" + + "Range: bytes={}\r\n".format(pselect_str) + + "uuid: pselect\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": "" +} + +res_pselect = {"headers": + "HTTP/1.1 206 Partial Content\r\n" + + "Accept-Ranges: bytes\r\n" + + "Cache-Control: max-age=200\r\n" + + "Content-Range: bytes {}/19\r\n".format(pselect_str) + + "Connection: close\r\n" + + 'Etag: "772102f4-56f4bc1e6d417"\r\n' + + "Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT\r\n" + + "\r\n", + "timestamp": "1469733493.993", + "body": body[1:10] +} + +server.addResponse("sessionlog.json", req_pselect, res_pselect) + +# cache range requests plugin remap +ts.Disk.remap_config.AddLines([ + 'map http://www.example.com http://127.0.0.1:{}'.format(server.Variables.Port) + + ' @plugin=cache_range_requests.so', + 'map http://parentselect http://127.0.0.1:{}'.format(server.Variables.Port) + + ' @plugin=cache_range_requests.so @pparam=ps_mode:cache_key_url', +]) + +# cache debug +ts.Disk.plugin_config.AddLine('xdebug.so') + +# minimal configuration +ts.Disk.records_config.update({ + 'proxy.config.diags.debug.enabled': 1, + 'proxy.config.diags.debug.tags': 'cache_range_requests', + 'proxy.config.http.cache.http': 1, + 'proxy.config.http.wait_for_cache': 1, +}) + +curl_and_args = 'curl -s -D /dev/stdout -o /dev/stderr -x localhost:{} -H "x-debug: x-cache"'.format(ts.Variables.port) + +# 0 Test - Fetch whole asset into cache +tr = Test.AddTestRun("full asset cache miss bypass") +ps = tr.Processes.Default +ps.StartBefore(server, ready=When.PortOpen(server.Variables.Port)) +ps.StartBefore(Test.Processes.ts, ready=When.PortOpen(ts.Variables.port)) +ps.Command = curl_and_args + ' http://www.example.com/path -H "uuid: full"' +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/full.stdout.gold" +ps.Streams.stderr = "gold/full.stderr.gold" +tr.StillRunningAfter = ts + +# test inner range +# 1 Test - Fetch range into cache +tr = Test.AddTestRun("inner range cache miss") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/path -r {} -H "uuid: inner"'.format(inner_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/inner.stdout.gold" +ps.Streams.stderr = "gold/inner.stderr.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: miss", "expected cache miss") +tr.StillRunningAfter = ts + +# 2 Test - Fetch from cache +tr = Test.AddTestRun("inner range cache hit") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/path -r {}'.format(inner_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/inner.stdout.gold" +ps.Streams.stderr = "gold/inner.stderr.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: hit", "expected cache hit") +tr.StillRunningAfter = ts + +# full range + +# 3 Test - 0- request +tr = Test.AddTestRun("0- request miss") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/path -r {} -H "uuid: frange"'.format(frange_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/frange.stdout.gold" +ps.Streams.stderr = "gold/frange.stderr.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: miss", "expected cache miss") +tr.StillRunningAfter = ts + +# 4 Test - 0- request +tr = Test.AddTestRun("0- request hit") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/path -r {}'.format(frange_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/frange.stdout.gold" +ps.Streams.stderr = "gold/frange.stderr.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: hit", "expected cache hit") +tr.StillRunningAfter = ts + +# end range + +# 5 Test - -5 request miss +tr = Test.AddTestRun("-5 request miss") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/path -r {} -H "uuid: last"'.format(last_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/last.stdout.gold" +ps.Streams.stderr = "gold/last.stderr.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: miss", "expected cache miss") +tr.StillRunningAfter = ts + +# 6 Test - -5 request hit +tr = Test.AddTestRun("-5 request hit") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/path -r {}'.format(last_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/last.stdout.gold" +ps.Streams.stderr = "gold/last.stderr.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: hit", "expected cache hit") +tr.StillRunningAfter = ts + +# Ensure 404's aren't getting cached + +# 7 Test - 404 +tr = Test.AddTestRun("404 request 1st") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/404 -r 0-' +ps.Streams.stdout = "gold/404.stdout.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: miss", "expected cache miss") +tr.StillRunningAfter = ts + +# 8 Test - 404 +tr = Test.AddTestRun("404 request 2nd") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/404 -r 0-' +ps.Streams.stdout = "gold/404.stdout.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: miss", "expected cache miss") +tr.StillRunningAfter = ts + +''' + +curl_and_args = 'curl -s -D /dev/stdout -o /dev/stderr -x localhost:{} -H "x-debug: x-parentselection-key"'.format(ts.Variables.port) + +# 9 Test - cache_key_url request +tr = Test.AddTestRun("cache_key_url request") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://parentselect/path -r {} -H "uuid: pselect"'.format(pselect_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/pselect.stdout.gold" +ps.Streams.stdout.Content = Testers.ContainsExpression( + "X-ParentSelection-Key: .*-bytes=", + "expected bytes in parent selection key", +) +tr.StillRunningAfter = ts +tr.StillRunningAfter = server + +# 10 Test - non cache_key_url request ... no X-ParentSelectionKey +tr = Test.AddTestRun("non cache_key_url request") +ps = tr.Processes.Default +ps.Command = curl_and_args + ' http://www.example.com/path -r {} -H "uuid: inner"'.format(inner_str) +ps.ReturnCode = 0 +ps.Streams.stdout = "gold/pselect_none.stdout.gold" +tr.StillRunningAfter = ts +tr.StillRunningAfter = server + +''' diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/404.stdout.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/404.stdout.gold new file mode 100644 index 0000000..f188050 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/404.stdout.gold @@ -0,0 +1,8 @@ +HTTP/1.1 404 Not Found +Server: `` +Date: `` +Age: 0 +Transfer-Encoding: chunked +Proxy-Connection: `` +X-Cache: miss +`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/frange.stderr.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/frange.stderr.gold new file mode 100644 index 0000000..24ad29c --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/frange.stderr.gold @@ -0,0 +1 @@ +lets go surfin now`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/frange.stdout.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/frange.stdout.gold new file mode 100644 index 0000000..6dae639 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/frange.stdout.gold @@ -0,0 +1,11 @@ +HTTP/1.1 206 Partial Content +Accept-Ranges: bytes +Cache-Control: max-age=500 +Content-Range: bytes 0-18/18 +Etag: "772102f4-56f4bc1e6d417" +Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT +Content-Length: 18 +Date: `` +Server: `` +X-Cache: `` +`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/full.stderr.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/full.stderr.gold new file mode 100644 index 0000000..24ad29c --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/full.stderr.gold @@ -0,0 +1 @@ +lets go surfin now`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/full.stdout.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/full.stdout.gold new file mode 100644 index 0000000..a485d26 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/full.stdout.gold @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Cache-Control: max-age=500 +Etag: "772102f4-56f4bc1e6d417" +Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT +Content-Length: 18 +Date: `` +Server: `` +X-Cache: miss +`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/inner.stderr.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/inner.stderr.gold new file mode 100644 index 0000000..1b0ef57 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/inner.stderr.gold @@ -0,0 +1 @@ + surfin`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/inner.stdout.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/inner.stdout.gold new file mode 100644 index 0000000..0628bfa --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/inner.stdout.gold @@ -0,0 +1,11 @@ +HTTP/1.1 206 Partial Content +Accept-Ranges: bytes +Cache-Control: max-age=500 +Content-Range: bytes 7-15/18 +Etag: "772102f4-56f4bc1e6d417" +Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT +Content-Length: 7 +Date: `` +Server: `` +X-Cache: `` +`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/last.stderr.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/last.stderr.gold new file mode 100644 index 0000000..9e4c8c4 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/last.stderr.gold @@ -0,0 +1 @@ +n now`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/last.stdout.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/last.stdout.gold new file mode 100644 index 0000000..5e2da00 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/last.stdout.gold @@ -0,0 +1,11 @@ +HTTP/1.1 206 Partial Content +Accept-Ranges: bytes +Cache-Control: max-age=500 +Content-Range: bytes 12-18/18 +Etag: "772102f4-56f4bc1e6d417" +Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT +Content-Length: 5 +Date: `` +Server: `` +X-Cache: `` +`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/pselect.stdout.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/pselect.stdout.gold new file mode 100644 index 0000000..11902d7 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/pselect.stdout.gold @@ -0,0 +1,11 @@ +HTTP/1.1 206 Partial Content +Accept-Ranges: bytes +Cache-Control: max-age=500 +Content-Range: bytes 1-10/18 +Etag: "772102f4-56f4bc1e6d417" +Last-Modified: Sat, 23 Jun 2018 09:27:29 GMT +Content-Length: 9 +Date: `` +Server: `` +X-ParentSelection: `` +`` diff --git a/tests/gold_tests/pluginTest/cache_range_requests/gold/pselect_none.stdout.gold b/tests/gold_tests/pluginTest/cache_range_requests/gold/pselect_none.stdout.gold new file mode 100644 index 0000000..dc9b155 --- /dev/null +++ b/tests/gold_tests/pluginTest/cache_range_requests/gold/pselect_none.stdout.gold @@ -0,0 +1,10 @@ +HTTP/1.1 206 Partial Content +Accept-Ranges: bytes +Cache-Control: `` +Content-Range: `` +Etag: `` +Last-Modified: `` +Content-Length: `` +Date: `` +Server: `` +``
