You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by el...@apache.org on 2022/05/11 18:39:22 UTC

[trafficserver] branch master updated: Add autest to cover updates to cache with alternates (#8779)

This is an automated email from the ASF dual-hosted git repository.

elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c5b18291 Add autest to cover updates to cache with alternates (#8779)
4c5b18291 is described below

commit 4c5b18291bd534f39a03b880bc7db3e06de43eed
Author: Chris McFarlen <ch...@mcfarlen.us>
AuthorDate: Wed May 11 13:39:16 2022 -0500

    Add autest to cover updates to cache with alternates (#8779)
    
    * Add autest to cover updates to cache with alternates
    
    * remove trailing line(autopep8)
    
    * add comments describing the requests
    
    * reduce delay and max-age on test
    
    * set cache object size to zero when incoming content length is zero
    
    * add demystifying comment
    
    Co-authored-by: Chris McFarlen <cm...@apple.com>
---
 iocore/cache/Cache.cc                              |   3 +
 tests/gold_tests/cache/alternate-caching.test.py   |  51 +++++++
 .../replay/alternate-caching-update-size.yaml      | 162 +++++++++++++++++++++
 3 files changed, 216 insertions(+)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index e22e56745..19b67ba9e 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -454,6 +454,9 @@ CacheVC::set_http_info(CacheHTTPInfo *ainfo)
   MIMEField *field = ainfo->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_LENGTH, MIME_LEN_CONTENT_LENGTH);
   if (field && !field->value_get_int64()) {
     f.allow_empty_doc = 1;
+    // Set the object size here to zero in case this is a cache replace where the new object
+    // length is zero but the old object was not.
+    ainfo->object_size_set(0);
   } else {
     f.allow_empty_doc = 0;
   }
diff --git a/tests/gold_tests/cache/alternate-caching.test.py b/tests/gold_tests/cache/alternate-caching.test.py
new file mode 100644
index 000000000..cf470680c
--- /dev/null
+++ b/tests/gold_tests/cache/alternate-caching.test.py
@@ -0,0 +1,51 @@
+'''
+Test the alternate caching features
+'''
+#  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 = '''
+Test the alternate caching feature.
+'''
+
+#
+# Verify disabled negative_revalidating behavior.
+#
+ts = Test.MakeATSProcess("ts-alternate-caching")
+ts.Disk.records_config.update({
+    'proxy.config.diags.debug.enabled': 1,
+    'proxy.config.diags.debug.tags': 'http|cache',
+
+    'proxy.config.http.cache.max_stale_age': 6,
+    'proxy.config.cache.select_alternate': 1,
+    'proxy.config.cache.limits.http.max_alts': 4,
+
+    # Try with and without this
+    'proxy.config.http.negative_revalidating_enabled': 1,
+    'proxy.config.http.negative_caching_enabled': 1,
+    'proxy.config.http.negative_caching_lifetime': 30
+
+})
+tr = Test.AddTestRun("Verify disabled negative revalidating behavior.")
+replay_file = "replay/alternate-caching-update-size.yaml"
+server = tr.AddVerifierServerProcess("server1", replay_file)
+server_port = server.Variables.http_port
+tr.AddVerifierClientProcess("client1", replay_file, http_ports=[ts.Variables.port])
+ts.Disk.remap_config.AddLine(
+    'map / http://127.0.0.1:{0}'.format(server_port)
+)
+tr.Processes.Default.StartBefore(ts)
+tr.StillRunningAfter = ts
diff --git a/tests/gold_tests/cache/replay/alternate-caching-update-size.yaml b/tests/gold_tests/cache/replay/alternate-caching-update-size.yaml
new file mode 100644
index 000000000..ddc4a4619
--- /dev/null
+++ b/tests/gold_tests/cache/replay/alternate-caching-update-size.yaml
@@ -0,0 +1,162 @@
+#  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.
+
+#
+# Verify negative_revalidating disabled behavior. This replay file assumes:
+#   * ATS is configured with negative_revalidating disabled.
+#   * max_stale_age is set to 6 seconds.
+#
+
+meta:
+  version: "1.0"
+
+  blocks:
+  - request_for_positive_max_age: &request_for_en_US
+      client-request:
+        method: "GET"
+        version: "1.1"
+        scheme: "http"
+        url: /path/request
+        headers:
+          fields:
+          - [ Host, example.com ]
+          - [ Accept, "*/*" ]
+          - [ Accept-Language, en_US ]
+        delay: 100ms
+
+  - request_for_positive_max_age: &request_for_es_US
+      client-request:
+        method: "GET"
+        version: "1.1"
+        scheme: "http"
+        url: /path/request
+        headers:
+          fields:
+          - [ Host, example.com ]
+          - [ Accept, "*/*" ]
+          - [ Accept-Language, es_US ]
+        delay: 100ms
+
+sessions:
+- transactions:
+  # These first two requests just store the two alternats for this url
+  - all: { headers: { fields: [[ uuid, 1 ]]}}
+    <<: *request_for_en_US
+
+    server-response:
+      status: 200
+      reason: OK
+      headers:
+        fields:
+        - [ Content-Length, 16 ]
+        - [ Cache-Control, max-age=1 ]
+        - [ Content-Language, en_US ]
+        - [ Vary, Accept-Language ]
+
+
+    proxy-response:
+      status: 200
+  - all: { headers: { fields: [[ uuid, 2 ]]}}
+    <<: *request_for_es_US
+
+    server-response:
+      status: 200
+      reason: OK
+      headers:
+        fields:
+        - [ Content-Length, 20 ]
+        - [ Cache-Control, max-age=1 ]
+        - [ Content-Language, es_US ]
+        - [ Vary, Accept-Language ]
+
+    proxy-response:
+      status: 200
+
+  # This request serves as a way to introduce a 5 second delay so we can replace the cache objects
+  - all: { headers: { fields: [[ uuid, 3 ]]}}
+    client-request:
+      method: "GET"
+      version: "1.1"
+      scheme: "http"
+      url: /path/request
+      headers:
+        fields:
+        - [ Host, example.com ]
+        - [ Accept, "*/*" ]
+        - [ Accept-Language, es_US ]
+      delay: 2s
+    server-response:
+      status: 500
+      reason: NOT USED
+      headers:
+        fields:
+        - [ Content-Length, 20 ]
+    proxy-response:
+      status: 200
+
+  # Replace the es_US alternate (this works fine)
+  - all: { headers: { fields: [[ uuid, 4 ]]}}
+    <<: *request_for_es_US
+
+    server-response:
+      status: 404
+      reason: OK
+      headers:
+        fields:
+        - [ Content-Length, 0 ]
+        - [ Cache-Control, max-age=10 ]
+        - [ Content-Language, es_US ]
+        - [ Vary, Accept-Language ]
+
+    proxy-response:
+      status: 404
+
+  # Replace the en_US alternate (this request breaks the cache)
+  - all: { headers: { fields: [[ uuid, 5 ]]}}
+    <<: *request_for_en_US
+
+    server-response:
+      status: 404
+      reason: OK
+      headers:
+        fields:
+        - [ Content-Length, 0 ]
+        - [ Cache-Control, max-age=1 ]
+        - [ Content-Language, en_US ]
+        - [ Vary, Accept-Language ]
+
+    proxy-response:
+      status: 404
+
+  # Expect a CL 0 response, but the server returns a chunked encoded, 16 byte response
+  - all: { headers: { fields: [[ uuid, 6 ]]}}
+    <<: *request_for_en_US
+
+    server-response:
+      status: 500
+      reason: NOT USED
+      headers:
+        fields:
+        - [ Content-Length, 0 ]
+        - [ Cache-Control, max-age=1 ]
+
+    proxy-response:
+      status: 404
+      headers:
+        fields:
+          - [ Content-Length, { value: "0", as: equal} ]
+
+