|
| 1 | +''' |
| 2 | +''' |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | + |
| 19 | +import os |
| 20 | +Test.Summary = ''' |
| 21 | +Test transactions and sessions for http2, making sure the two continuations catch the same number of hooks. |
| 22 | +''' |
| 23 | +Test.SkipUnless( |
| 24 | + Condition.HasProgram("curl", "Curl needs to be installed on system for this test to work"), |
| 25 | + Condition.HasCurlFeature('http2') |
| 26 | +) |
| 27 | +Test.ContinueOnFail = True |
| 28 | +# Define default ATS |
| 29 | +ts = Test.MakeATSProcess("ts", select_ports=False, command="traffic_manager") |
| 30 | +server = Test.MakeOriginServer("server") |
| 31 | + |
| 32 | +Test.testName = "" |
| 33 | +request_header = {"headers": "GET / HTTP/1.1\r\nHost: double_h2.test\r\n\r\n", "timestamp": "1469733493.993", "body": ""} |
| 34 | +# expected response from the origin server |
| 35 | +response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", |
| 36 | + "timestamp": "1469733493.993", "body": ""} |
| 37 | + |
| 38 | +# add response to the server dictionary |
| 39 | +server.addResponse("sessionfile.log", request_header, response_header) |
| 40 | + |
| 41 | +# add ssl materials like key, certificates for the server |
| 42 | +ts.addSSLfile("ssl/server.pem") |
| 43 | +ts.addSSLfile("ssl/server.key") |
| 44 | + |
| 45 | +# add port and remap rule |
| 46 | +ts.Variables.ssl_port = 4443 |
| 47 | +ts.Disk.remap_config.AddLine( |
| 48 | + 'map http://double_h2.test:{0} http://127.0.0.1:{1}'.format(ts.Variables.port, server.Variables.Port) |
| 49 | +) |
| 50 | + |
| 51 | +ts.Disk.ssl_multicert_config.AddLine( |
| 52 | + 'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key' |
| 53 | +) |
| 54 | + |
| 55 | +ts.Disk.records_config.update({ |
| 56 | + 'proxy.config.diags.debug.enabled': 1, |
| 57 | + 'proxy.config.diags.debug.tags': 'continuations_verify.*', |
| 58 | + 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir), |
| 59 | + 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir), |
| 60 | + 'proxy.config.http.cache.http': 0, # disable cache to simply the test. |
| 61 | + 'proxy.config.cache.enable_read_while_writer': 0, |
| 62 | + # enable ssl port |
| 63 | + 'proxy.config.http.server_ports': '{0} {1}:proto=http2;http:ssl'.format(ts.Variables.port, ts.Variables.ssl_port), |
| 64 | + 'proxy.config.ssl.client.verify.server': 0, |
| 65 | + 'proxy.config.ssl.server.cipher_suite': 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2', |
| 66 | + 'proxy.config.http2.max_concurrent_streams_in': 65535 |
| 67 | +}) |
| 68 | + |
| 69 | +# add plugin to assist with test metrics |
| 70 | +Test.PreparePlugin(os.path.join(Test.Variables.AtsTestToolsDir, |
| 71 | + 'plugins', 'continuations_verify.cc'), ts) |
| 72 | + |
| 73 | +comparator_command = ''' |
| 74 | +if test "`traffic_ctl metric get continuations_verify.{0}.close.1 | cut -d ' ' -f 2`" -eq "`traffic_ctl metric get continuations_verify.{0}.close.2 | cut -d ' ' -f 2`" ; then\ |
| 75 | + echo yes;\ |
| 76 | + else \ |
| 77 | + echo no; \ |
| 78 | + fi; |
| 79 | + ''' |
| 80 | + |
| 81 | +# curl with http2 |
| 82 | +cmd = 'curl --http2 -k -vs https://127.0.0.1:{0}/'.format(ts.Variables.ssl_port) |
| 83 | +numberOfRequests = 25 |
| 84 | + |
| 85 | +tr = Test.AddTestRun() |
| 86 | + |
| 87 | +# Create a bunch of curl commands to be executed in parallel. Default.Process is set in SpawnCommands. |
| 88 | +ps = tr.SpawnCommands(cmdstr=cmd, count=numberOfRequests) |
| 89 | +tr.Processes.Default.Env = ts.Env |
| 90 | + |
| 91 | +# Execution order is: ts/server, ps(curl cmds), Default Process. |
| 92 | +tr.Processes.Default.StartBefore( |
| 93 | + server, ready=When.PortOpen(server.Variables.Port)) |
| 94 | +# Adds a delay once the ts port is ready. This is because we cannot test the ts state. |
| 95 | +tr.Processes.Default.StartBefore(ts, ready=10) |
| 96 | +ts.StartAfter(*ps) |
| 97 | +server.StartAfter(*ps) |
| 98 | +tr.StillRunningAfter = ts |
| 99 | + |
| 100 | +# Watch the records snapshot file. |
| 101 | +records = ts.Disk.File(os.path.join(ts.Variables.RUNTIMEDIR, "records.snap")) |
| 102 | + |
| 103 | +# number of sessions/transactions opened and closed are equal |
| 104 | +tr = Test.AddTestRun() |
| 105 | +tr.DelayStart = 10 # wait for stats to be updated |
| 106 | +tr.Processes.Default.Command = comparator_command.format('ssn') |
| 107 | +tr.Processes.Default.ReturnCode = 0 |
| 108 | +tr.Processes.Default.Env = ts.Env |
| 109 | +tr.Processes.Default.Streams.stdout = Testers.ContainsExpression("yes", 'should verify contents') |
| 110 | +tr.StillRunningAfter = ts |
| 111 | + |
| 112 | +# for debugging session number |
| 113 | +ssn1 = tr.Processes.Process("session1", 'traffic_ctl metric get continuations_verify.ssn.close.1 > ssn1') |
| 114 | +ssn2 = tr.Processes.Process("session2", 'traffic_ctl metric get continuations_verify.ssn.close.2 > ssn2') |
| 115 | +ssn1.Env = ts.Env |
| 116 | +ssn2.Env = ts.Env |
| 117 | +tr.Processes.Default.StartBefore(ssn1) |
| 118 | +tr.Processes.Default.StartBefore(ssn2) |
| 119 | + |
| 120 | +tr = Test.AddTestRun() |
| 121 | +tr.Processes.Default.Command = comparator_command.format('txn') |
| 122 | +tr.Processes.Default.ReturnCode = 0 |
| 123 | +tr.Processes.Default.Env = ts.Env |
| 124 | +tr.Processes.Default.Streams.stdout = Testers.ContainsExpression("yes", 'should verify contents') |
| 125 | +tr.StillRunningAfter = ts |
| 126 | + |
| 127 | +# for debugging transaction number |
| 128 | +txn1 = tr.Processes.Process("transaction1", 'traffic_ctl metric get continuations_verify.txn.close.1 > txn1') |
| 129 | +txn2 = tr.Processes.Process("transaction2", 'traffic_ctl metric get continuations_verify.txn.close.2 > txn2') |
| 130 | +txn1.Env = ts.Env |
| 131 | +txn2.Env = ts.Env |
| 132 | +tr.Processes.Default.StartBefore(txn1) |
| 133 | +tr.Processes.Default.StartBefore(txn2) |
| 134 | + |
| 135 | +# session count is positive, |
| 136 | +tr = Test.AddTestRun() |
| 137 | +tr.Processes.Default.Command = "traffic_ctl metric get continuations_verify.ssn.close.1" |
| 138 | +tr.Processes.Default.ReturnCode = 0 |
| 139 | +tr.Processes.Default.Env = ts.Env |
| 140 | +tr.Processes.Default.Streams.stdout = Testers.ExcludesExpression(" 0", 'should be nonzero') |
| 141 | +tr.StillRunningAfter = ts |
| 142 | + |
| 143 | +# and we receive the same number of transactions as we asked it to make |
| 144 | +tr = Test.AddTestRun() |
| 145 | +tr.Processes.Default.Command = "traffic_ctl metric get continuations_verify.txn.close.1" |
| 146 | +tr.Processes.Default.ReturnCode = 0 |
| 147 | +tr.Processes.Default.Env = ts.Env |
| 148 | +tr.Processes.Default.Streams.stdout = Testers.ContainsExpression( |
| 149 | + "continuations_verify.txn.close.1 {}".format(numberOfRequests), 'should be the number of transactions we made') |
| 150 | +tr.StillRunningAfter = ts |
0 commit comments