traeak commented on a change in pull request #8723:
URL: https://github.com/apache/trafficserver/pull/8723#discussion_r835582416



##########
File path: tests/gold_tests/pluginTest/slice/slice_prefetch.test.py
##########
@@ -0,0 +1,178 @@
+'''
+'''
+#  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.
+
+Test.Summary = '''
+slice plugin prefetch feature test
+'''
+
+# Test description:
+# Fill origin server with range requests
+# Request content through slice plugin with varied prefetch counts
+
+Test.SkipUnless(
+    Condition.PluginExists('slice.so'),
+    Condition.PluginExists('cache_range_requests.so'),
+)
+Test.ContinueOnFail = False
+
+# configure origin server, lookup by Range header
+server = Test.MakeOriginServer("server", lookup_key="{%Range}")
+
+# Define ATS and configure
+ts = Test.MakeATSProcess("ts", command="traffic_server")
+
+block_bytes_1 = 7
+block_bytes_2 = 5
+body = "lets go surfin now"
+bodylen = len(body)
+
+request_header = {"headers":
+                  "GET /path HTTP/1.1\r\n" +
+                  "Host: origin\r\n" +
+                  "\r\n",
+                  "timestamp": "1469733493.993",
+                  "body": "",
+                  }
+
+response_header = {"headers":
+                   "HTTP/1.1 200 OK\r\n" +
+                   "Connection: close\r\n" +
+                   "Cache-Control: public, max-age=500\r\n" +
+                   "\r\n",
+                   "timestamp": "1469733493.993",
+                   "body": body,
+                   }
+
+server.addResponse("sessionlog.json", request_header, response_header)
+
+# Autest OS doesn't support range request, must manually add requests/responses
+for block_bytes in [block_bytes_1, block_bytes_2]:
+    for i in range(bodylen // block_bytes + 1):
+        b0 = i * block_bytes
+        b1 = b0 + block_bytes - 1
+        req_header = {"headers":
+                      "GET /path HTTP/1.1\r\n" +
+                      "Host: *\r\n" +
+                      "Accept: */*\r\n" +
+                      f"Range: bytes={b0}-{b1}\r\n" +
+                      "\r\n",
+                      "timestamp": "1469733493.993",
+                      "body": ""
+                      }
+        if (b1 > bodylen - 1):
+            b1 = bodylen - 1
+        resp_header = {"headers":
+                       "HTTP/1.1 206 Partial Content\r\n" +
+                       "Accept-Ranges: bytes\r\n" +
+                       "Cache-Control: public, max-age=500\r\n" +
+                       f"Content-Range: bytes {b0}-{b1}/{bodylen}\r\n" +
+                       "Connection: close\r\n" +
+                       "\r\n",
+                       "timestamp": "1469733493.993",
+                       "body": body[b0:b1 + 1]
+                       }
+        server.addResponse("sessionlog.json", req_header, resp_header)
+
+curl_and_args = 'curl -s -D /dev/stdout -o /dev/stderr -x 
http://127.0.0.1:{}'.format(ts.Variables.port)
+
+ts.Disk.remap_config.AddLines([
+    f'map http://sliceprefetch1bytes1/ 
http://127.0.0.1:{server.Variables.Port}' +
+    f' @plugin=slice.so @pparam=--blockbytes-test={block_bytes_1} 
@pparam=--prefetch-count=1' +
+    ' @plugin=cache_range_requests.so',
+    f'map http://sliceprefetch2bytes1/ 
http://127.0.0.1:{server.Variables.Port}' +
+    f' @plugin=slice.so @pparam=--blockbytes-test={block_bytes_1} 
@pparam=--prefetch-count=2' +
+    ' @plugin=cache_range_requests.so',
+    f'map http://sliceprefetch1bytes2/ 
http://127.0.0.1:{server.Variables.Port}' +
+    f' @plugin=slice.so @pparam=--blockbytes-test={block_bytes_2} 
@pparam=--prefetch-count=1' +
+    ' @plugin=cache_range_requests.so',
+    f'map http://sliceprefetch2bytes2/ 
http://127.0.0.1:{server.Variables.Port}' +
+    f' @plugin=slice.so @pparam=--blockbytes-test={block_bytes_2} 
@pparam=--prefetch-count=2' +
+    ' @plugin=cache_range_requests.so',
+])
+
+ts.Disk.records_config.update({
+    'proxy.config.diags.debug.enabled': 1,
+    'proxy.config.diags.debug.tags': 'slice|cache_range_requests|pvc',
+})
+
+# 0 Test - Full object slice with only next block prefetched in background, 
block bytes= 7
+tr = Test.AddTestRun("Full object slice with only next block prefetched in 
background, block bytes= 7")
+ps = tr.Processes.Default
+ps.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
+ps.StartBefore(Test.Processes.ts)
+ps.Command = curl_and_args + ' http://sliceprefetch1bytes1/path'
+ps.ReturnCode = 0
+ps.Streams.stderr = "gold/slice_200.stderr.gold"
+ps.Streams.stdout.Content = Testers.ContainsExpression("200 OK", "expected 200 
OK response")
+tr.StillRunningAfter = ts
+
+# 1 Test - Full object slice with nest 2 blocks prefetched in background, 
block bytes= 7
+tr = Test.AddTestRun("Test - Full object slice with nest 2 blocks prefetched 
in background, block bytes= 7")
+ps = tr.Processes.Default
+ps.Command = curl_and_args + ' http://sliceprefetch2bytes1/path'
+ps.ReturnCode = 0
+ps.Streams.stderr = "gold/slice_200.stderr.gold"
+ps.Streams.stdout.Content = Testers.ContainsExpression("200 OK", "expected 200 
OK response")
+tr.StillRunningAfter = ts
+
+# 2 Test - Full object slice with only next block prefetched in background, 
block bytes= 5
+tr = Test.AddTestRun("Full object slice with only next block prefetched in 
background, block bytes= 5")
+ps = tr.Processes.Default
+ps.Command = curl_and_args + ' http://sliceprefetch1bytes2/path'
+ps.ReturnCode = 0
+ps.Streams.stderr = "gold/slice_200.stderr.gold"
+ps.Streams.stdout.Content = Testers.ContainsExpression("200 OK", "expected 200 
OK response")
+tr.StillRunningAfter = ts
+
+# 3 Test - Full object slice with nest 2 blocks prefetched in background, 
block bytes= 5
+tr = Test.AddTestRun("Full object slice with nest 2 blocks prefetched in 
background, block bytes= 5")
+ps = tr.Processes.Default
+ps.Command = curl_and_args + ' http://sliceprefetch2bytes2/path'
+ps.ReturnCode = 0
+ps.Streams.stderr = "gold/slice_200.stderr.gold"
+ps.Streams.stdout.Content = Testers.ContainsExpression("200 OK", "expected 200 
OK response")
+tr.StillRunningAfter = ts
+
+# 4 Test - Whole asset via range
+tr = Test.AddTestRun("Whole asset via range")
+ps = tr.Processes.Default
+ps.Command = curl_and_args + ' http://sliceprefetch1bytes1/path' + ' -r 0-'
+ps.ReturnCode = 0
+ps.Streams.stderr = "gold/slice_206.stderr.gold"
+ps.Streams.stdout.Content = Testers.ContainsExpression("206 Partial Content", 
"expected 206 response")
+ps.Streams.stdout.Content += Testers.ContainsExpression("Content-Range: bytes 
0-17/18", "mismatch byte content response")
+tr.StillRunningAfter = ts
+
+# 5 Test - Non aligned slice request
+tr = Test.AddTestRun("Non aligned slice request")
+ps = tr.Processes.Default
+ps.Command = curl_and_args + ' http://sliceprefetch1bytes1/path' + ' -r 5-16'
+ps.ReturnCode = 0
+ps.Streams.stderr = "gold/slice_mid.stderr.gold"
+ps.Streams.stdout.Content = Testers.ContainsExpression("206 Partial Content", 
"expected 206 response")
+ps.Streams.stdout.Content += Testers.ContainsExpression("Content-Range: bytes 
5-16/18", "mismatch byte content response")
+tr.StillRunningAfter = ts
+
+# 6 Test - special case, begin inside last slice block but outside asset len
+tr = Test.AddTestRun("Invalid end range request, 416")
+beg = len(body) + 1
+end = beg + block_bytes
+ps = tr.Processes.Default
+ps.Command = curl_and_args + ' http://sliceprefetch1bytes1/path' + ' -r 
{}-{}'.format(beg, end)

Review comment:
       we've been switching over to this format convention for autests:
   f'http://sliceprefetch1bytes1/path -r {beg}-{end}'




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to