JosiahWI commented on issue #9275: URL: https://github.com/apache/trafficserver/issues/9275#issuecomment-2221205565
```python # 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 functools from typing import Any, Callable, Dict, Optional from ports import get_port Test.Summary = 'Tests SNI port-based routing' TestParams = Dict[str, Any] class TestRamdiskRedirect: """Configure a test for reproducing #9275.""" replay_filepath_one: str = "ramdisk-redirect.replay.yaml" replay_filepath_two: str = "ramdisk-redirect-ok.replay.yaml" client_counter: int = 0 server_counter: int = 0 ts_counter: int = 0 def __init__(self, name: str, /, autorun) -> None: """Initialize the test. :param name: The name of the test. """ self.name = name self.autorun = autorun def _init_run(self) -> "TestRun": """Initialize processes for the test run.""" tr = Test.AddTestRun(self.name) server_one = TestRamdiskRedirect.configure_server(tr, "oof.com") self._configure_traffic_server(tr, server_one) dns = TestRamdiskRedirect.configure_dns(tr, server_one, self._dns_port) tr.Processes.Default.StartBefore(server_one) tr.Processes.Default.StartBefore(dns) tr.Processes.Default.StartBefore(self._ts) return { "tr": tr, "ts": self._ts, "server_one": server_one, "port_one": self._port_one, } @classmethod def runner(cls, name: str, autorun: bool = True) -> Optional[Callable]: """Create a runner for a test case. :param autorun: Run the test case once it's set up. Default is True. """ test = cls(name, autorun=autorun)._prepare_test_case return test def _prepare_test_case(self, func: Callable) -> Callable: """Set up a test case and possibly run it. :param func: The test case to set up. """ functools.wraps(func) test_params = self._init_run() def wrapper(*args, **kwargs) -> Any: return func(test_params, *args, **kwargs) if self.autorun: wrapper() return wrapper @staticmethod def configure_server(tr: "TestRun", domain: str): server = tr.AddVerifierServerProcess(f"server{TestRamdiskRedirect.server_counter}.{domain}", TestRamdiskRedirect.replay_filepath_one, other_args="--format \"{url}\"") TestRamdiskRedirect.server_counter += 1 return server @staticmethod def configure_dns(tr: "TestRun", server_one: "Process", dns_port: int): dns = tr.MakeDNServer("dns", port=dns_port, default="127.0.0.1") return dns def _configure_traffic_server(self, tr: "TestRun", server_one: "Process"): """Configure Traffic Server. :param tr: The TestRun object to associate the ts process with. """ ts = tr.MakeATSProcess(f"ts-{TestRamdiskRedirect.ts_counter}", select_ports=False, enable_tls=True, enable_cache=True) TestRamdiskRedirect.ts_counter += 1 self._port_one = get_port(ts, "PortOne") self._dns_port = get_port(ts, "DNSPort") ts.Disk.records_config.update( { 'proxy.config.http.server_ports': f"{self._port_one}", 'proxy.config.diags.debug.enabled': 1, 'proxy.config.diags.debug.tags': "cache|dns|http|redirect|remap", 'proxy.config.dns.nameservers': f"127.0.0.1:{self._dns_port}", 'proxy.config.dns.resolv_conf': 'NULL', 'proxy.config.http.redirect.actions': "self:follow", 'proxy.config.http.number_of_redirections': 1, }) ts.Disk.remap_config.AddLine(f"map oof.com http://oof.backend.com:{server_one.Variables.http_port}") ts.Disk.storage_config.AddLine("storage 128M") ts.Disk.hosting_config.AddLine("hostname=* volume=1") ts.Disk.volume_config.AddLine("volume=1 scheme=http size=100% ramcache=false") self._ts = ts # Tests start. @TestRamdiskRedirect.runner("Redirect to same origin with cache - boom!") def test1(params: TestParams) -> None: # This sends a request to origin, which returns 307 temporary redirect with # a different path on the same origin. ATS is configured to follow the # redirect, so it prepares to hit the same origin with the new path in the # `location` header of the 307 response. Before issuing the request to # origin, we just need to check the cache. The lock on the cache hasn't # been released after the 307 response, so ATS hangs, and the connection # dies after a timeout. client = params["tr"].AddVerifierClientProcess( f"client0", TestRamdiskRedirect.replay_filepath_one, http_ports=[params["port_one"]], other_args="--format \"{url}\" --keys \"/a/path/resource\"") params["tr"].Processes.Default.ReturnCode = 0 ``` -- 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]
