|
| 1 | +''' |
| 2 | +Test proxy serving stale content when DNS lookup fails |
| 3 | +''' |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 5 | +# or more contributor license agreements. See the NOTICE file |
| 6 | +# distributed with this work for additional information |
| 7 | +# regarding copyright ownership. The ASF licenses this file |
| 8 | +# to you under the Apache License, Version 2.0 (the |
| 9 | +# "License"); you may not use this file except in compliance |
| 10 | +# with the License. You may obtain a copy of the License at |
| 11 | +# |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +# See the License for the specific language governing permissions and |
| 18 | +# limitations under the License. |
| 19 | + |
| 20 | +Test.ContinueOnFail = True |
| 21 | +# Set up hierarchical caching processes |
| 22 | +ts_child = Test.MakeATSProcess("ts_child") |
| 23 | +ts_parent = Test.MakeATSProcess("ts_parent") |
| 24 | +server_name = "http://unknown.domain.com/" |
| 25 | + |
| 26 | +Test.testName = "STALE" |
| 27 | + |
| 28 | +# Config child proxy to route to parent proxy |
| 29 | +ts_child.Disk.records_config.update({ |
| 30 | + 'proxy.config.url_remap.pristine_host_hdr': 1, |
| 31 | + 'proxy.config.http.cache.max_stale_age': 10, |
| 32 | + 'proxy.config.http.parent_proxy.self_detect': 0, |
| 33 | +}) |
| 34 | +ts_child.Disk.parent_config.AddLine( |
| 35 | + f'dest_domain=. parent=localhost:{ts_parent.Variables.port} round_robin=consistent_hash go_direct=false' |
| 36 | +) |
| 37 | +ts_child.Disk.remap_config.AddLine( |
| 38 | + f'map http://localhost:{ts_child.Variables.port} {server_name}' |
| 39 | +) |
| 40 | + |
| 41 | +# Configure parent proxy |
| 42 | +ts_parent.Disk.records_config.update({ |
| 43 | + 'proxy.config.url_remap.pristine_host_hdr': 1, |
| 44 | + 'proxy.config.http.cache.max_stale_age': 10, |
| 45 | +}) |
| 46 | +ts_parent.Disk.remap_config.AddLine( |
| 47 | + f'map http://localhost:{ts_parent.Variables.port} {server_name}' |
| 48 | +) |
| 49 | +ts_parent.Disk.remap_config.AddLine( |
| 50 | + f'map {server_name} {server_name}' |
| 51 | +) |
| 52 | + |
| 53 | +# Object to push to proxies |
| 54 | +stale_5 = "HTTP/1.1 200 OK\nServer: ATS/10.0.0\nAccept-Ranges: bytes\nContent-Length: 6\nCache-Control: public, max-age=5\n\nCACHED" |
| 55 | +stale_10 = "HTTP/1.1 200 OK\nServer: ATS/10.0.0\nAccept-Ranges: bytes\nContent-Length: 6\nCache-Control: public, max-age=10\n\nCACHED" |
| 56 | + |
| 57 | + |
| 58 | +# Testing scenarios |
| 59 | +child_curl_request = ( |
| 60 | + # Test child serving stale with failed DNS OS lookup |
| 61 | + f'curl -X PUSH -d "{stale_5}" "http://localhost:{ts_child.Variables.port}";' |
| 62 | + f'curl -X PUSH -d "{stale_10}" "http://localhost:{ts_parent.Variables.port}";' |
| 63 | + f'sleep 7; curl -s -v http://localhost:{ts_child.Variables.port};' |
| 64 | + f'sleep 15; curl -s -v http://localhost:{ts_child.Variables.port};' |
| 65 | + # Test parent serving stale with failed DNS OS lookup |
| 66 | + f'curl -X PUSH -d "{stale_5}" "http://localhost:{ts_parent.Variables.port}";' |
| 67 | + f'sleep 7; curl -s -v http://localhost:{ts_parent.Variables.port};' |
| 68 | + f'sleep 15; curl -s -v http://localhost:{ts_parent.Variables.port};' |
| 69 | +) |
| 70 | + |
| 71 | +# Test case for when parent server is down but child proxy can serve cache object |
| 72 | +tr = Test.AddTestRun() |
| 73 | +tr.Processes.Default.Command = child_curl_request |
| 74 | +tr.Processes.Default.ReturnCode = 0 |
| 75 | +tr.Processes.Default.StartBefore(ts_child) |
| 76 | +tr.Processes.Default.StartBefore(ts_parent) |
| 77 | +tr.Processes.Default.Streams.stderr = "gold/serve_stale_dns_fail.gold" |
| 78 | +tr.StillRunningAfter = ts_child |
| 79 | +tr.StillRunningAfter = ts_parent |
0 commit comments