Skip to content

Commit 94de5ea

Browse files
committed
Add ssn and txn tests for HTTP2
1 parent 130970f commit 94de5ea

File tree

8 files changed

+436
-35
lines changed

8 files changed

+436
-35
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'''
2+
Tools to help with TestRun commands
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+
21+
# allows the same command to be repeatedly run in parallel.
22+
#
23+
# example usage:
24+
# curlcmd = 'curl -vs -k https:127.0.0.1:{port}'.format(port = ts.Variables.port)
25+
#
26+
# tr = Test.AddTestRun()
27+
# ps = tr.SpawnCommands(cmdstr=cmdstr, count=25)
28+
# tr.Processes.Default.StartBefore(ts)
29+
# ts.StartAfter(*ps)
30+
# tr.StillRunningAfter = ts
31+
#
32+
# Note that by default, the Default Process is created in this function.
33+
34+
def spawn_commands(self, cmdstr, count, retcode = 0, use_default=True):
35+
ret=[]
36+
37+
if use_default:
38+
count = int(count) - 1
39+
for cnt in range(0,count):
40+
ret.append(
41+
self.Processes.Process(
42+
name="cmdline-{num}".format(num=cnt),
43+
cmdstr = cmdstr,
44+
returncode = retcode
45+
)
46+
)
47+
if use_default:
48+
self.Processes.Default.Command = cmdstr
49+
self.Processes.Default.ReturnCode = retcode
50+
self.Processes.Default.StartBefore(
51+
*ret
52+
)
53+
return ret
54+
55+
ExtendTestRun(spawn_commands, name="SpawnCommands")

tests/gold_tests/continuations/double.test.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
# limitations under the License.
1818

1919
import os
20-
from random import randint
2120
Test.Summary = '''
22-
Test transactions and sessions, making sure they open and close in the proper order.
21+
Test transactions and sessions, making sure two continuations catch the same number of hooks.
2322
'''
24-
# need Apache Benchmark. For RHEL7, this is httpd-tools
2523
Test.SkipUnless(
26-
Condition.HasProgram("ab", "apache benchmark (httpd-tools) needs to be installed on system for this test to work")
24+
Condition.HasProgram("curl", "Curl needs to be installed on system for this test to work")
2725
)
2826
Test.ContinueOnFail = True
2927
# Define default ATS
@@ -50,15 +48,22 @@
5048
'map http://double.test:{0} http://127.0.0.1:{1}'.format(ts.Variables.port, server.Variables.Port)
5149
)
5250

53-
numberOfRequests = randint(1000, 1500)
51+
cmd = 'curl -vs http://127.0.0.1:{0}'.format(ts.Variables.port)
52+
numberOfRequests = 25
5453

55-
# Make a *ton* of calls to the proxy!
5654
tr = Test.AddTestRun()
57-
tr.Processes.Default.Command = 'ab -n {0} -c 10 http://127.0.0.1:{1}/;sleep 5'.format(numberOfRequests, ts.Variables.port)
58-
tr.Processes.Default.ReturnCode = 0
59-
# time delay as proxy.config.http.wait_for_cache could be broken
60-
tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
61-
tr.Processes.Default.StartBefore(ts, ready=When.PortOpen(ts.Variables.port))
55+
56+
# Create a bunch of curl commands to be executed in parallel. Default.Process is set in SpawnCommands.
57+
ps = tr.SpawnCommands(cmdstr=cmd, count=numberOfRequests)
58+
tr.Processes.Default.Env = ts.Env
59+
60+
# Execution order is: ts/server, ps(curl cmds), Default Process.
61+
tr.Processes.Default.StartBefore(
62+
server, ready=When.PortOpen(server.Variables.Port))
63+
# Adds a delay once the ts port is ready. This is because we cannot test the ts state.
64+
tr.Processes.Default.StartBefore(ts, ready=10)
65+
ts.StartAfter(*ps)
66+
server.StartAfter(*ps)
6267
tr.StillRunningAfter = ts
6368

6469
comparator_command = '''
@@ -71,14 +76,9 @@
7176

7277
records = ts.Disk.File(os.path.join(ts.Variables.RUNTIMEDIR, "records.snap"))
7378

74-
75-
def file_is_ready():
76-
return os.path.exists(records.AbsPath)
77-
78-
7979
# number of sessions/transactions opened and closed are equal
8080
tr = Test.AddTestRun()
81-
tr.DelayStart=10
81+
tr.DelayStart = 10 # wait for stats to be updated
8282
tr.Processes.Default.Command = comparator_command.format('ssn')
8383
tr.Processes.Default.ReturnCode = 0
8484
tr.Processes.Default.Env = ts.Env
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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

tests/gold_tests/transaction/txn.test.py renamed to tests/gold_tests/continuations/openclose.test.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
# limitations under the License.
1818

1919
import os
20-
from random import randint
2120
Test.Summary = '''
2221
Test transactions and sessions, making sure they open and close in the proper order.
2322
'''
24-
# need Apache Benchmark. For RHEL7, this is httpd-tools
23+
2524
Test.SkipUnless(
26-
Condition.HasProgram(
27-
"ab", "apache benchmark (httpd-tools) needs to be installed on system for this test to work")
25+
Condition.HasProgram("curl", "Curl needs to be installed on system for this test to work")
2826
)
2927

3028
# Define default ATS
@@ -33,7 +31,7 @@
3331
server = Test.MakeOriginServer("server")
3432

3533
Test.testName = ""
36-
request_header = {"headers": "GET / HTTP/1.1\r\nHost: txn.test\r\n\r\n",
34+
request_header = {"headers": "GET / HTTP/1.1\r\nHost: oc.test\r\n\r\n",
3735
"timestamp": "1469733493.993", "body": ""}
3836
# expected response from the origin server
3937
response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n",
@@ -52,27 +50,31 @@
5250
})
5351

5452
ts.Disk.remap_config.AddLine(
55-
'map http://txn.test:{0} http://127.0.0.1:{1}'.format(
53+
'map http://oc.test:{0} http://127.0.0.1:{1}'.format(
5654
ts.Variables.port, server.Variables.Port)
5755
)
5856

59-
numberOfRequests = randint(1000, 1500)
57+
cmd = 'curl -vs http://127.0.0.1:{0}'.format(ts.Variables.port)
58+
numberOfRequests = 25
6059

61-
# Make a *ton* of calls to the proxy!
6260
tr = Test.AddTestRun()
63-
tr.Processes.Default.Command = 'ab -n {0} -c 10 -X 127.0.0.1:{1} http://txn.test/;sleep 5'.format(
64-
numberOfRequests, ts.Variables.port)
65-
tr.Processes.Default.ReturnCode = 0
66-
# time delay as proxy.config.http.wait_for_cache could be broken
61+
62+
# Create a bunch of curl commands to be executed in parallel. Default.Process is set in SpawnCommands.
63+
ps = tr.SpawnCommands(cmdstr=cmd, count=numberOfRequests)
64+
tr.Processes.Default.Env = ts.Env
65+
66+
# Execution order is: ts/server, ps(curl cmds), Default Process.
6767
tr.Processes.Default.StartBefore(
6868
server, ready=When.PortOpen(server.Variables.Port))
69-
tr.Processes.Default.StartBefore(ts, ready=When.PortOpen(ts.Variables.port))
69+
# Adds a delay once the ts port is ready. This is because we cannot test the ts state.
70+
tr.Processes.Default.StartBefore(ts, ready=10)
71+
ts.StartAfter(*ps)
72+
server.StartAfter(*ps)
7073
tr.StillRunningAfter = ts
7174

7275
# Watch the records snapshot file.
7376
records = ts.Disk.File(os.path.join(ts.Variables.RUNTIMEDIR, "records.snap"))
7477

75-
7678
# Check our work on traffic_ctl
7779
# no errors happened,
7880
tr = Test.AddTestRun()
@@ -130,4 +132,4 @@
130132
tr.Processes.Default.Streams.stdout = Testers.ContainsExpression(
131133
"ssntxnorder_verify.txn.start {}".format(numberOfRequests), 'should be the number of transactions we made')
132134
tr.StillRunningAfter = ts
133-
tr.StillRunningAfter = server
135+
tr.StillRunningAfter = server

0 commit comments

Comments
 (0)