Last active
January 17, 2019 17:17
-
-
Save dragon512/2687900fe208e07a0be957666fec5a19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
Test.Summary = ''' | |
Test a basic regex_revalidate | |
''' | |
# need Curl | |
Test.SkipUnless( | |
Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"), | |
Condition.PluginExists('regex_revalidate.so'), | |
Condition.PluginExists('xdebug.so') | |
) | |
Test.ContinueOnFail = False | |
# configure origin server | |
server = Test.MakeOriginServer("server") | |
# Define ATS and configure | |
ts = Test.MakeATSProcess("ts", command="traffic_manager") | |
#**testname is required** | |
#testName = "regex_reval" | |
# default root | |
request_header_0 = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""} | |
response_header_0 = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\nCache-Control: max-age=300\r\n\r\n", "timestamp": "1469733493.993", "body": "xxx"} | |
# cache item path1 | |
request_header_1 = {"headers": | |
"GET /path1 HTTP/1.1\r\n" + | |
"Host: www.example.com\r\n" + | |
"\r\n", | |
"timestamp": "1469733493.993", | |
"body": "" | |
} | |
response_header_1 = {"headers": | |
"HTTP/1.1 200 OK\r\n" + | |
"Connection: close\r\n" + | |
'Etag: "12"\r\n' + | |
"Cache-Control: max-age=600,public\r\n" + | |
"\r\n", | |
"timestamp": "1469733493.993", | |
"body": "abc" | |
} | |
# cache item path1a | |
request_header_2 = {"headers": | |
"GET /path1a HTTP/1.1\r\n" + | |
"Host: www.example.com\r\n" + | |
"\r\n", | |
"timestamp": "1469733493.993", | |
"body": "" | |
} | |
response_header_2 = {"headers": | |
"HTTP/1.1 200 OK\r\n" + | |
"Connection: close\r\n" + | |
'Etag: "42"\r\n' + | |
"Cache-Control: max-age=600,public\r\n" + | |
"\r\n", | |
"timestamp": "1469733493.993", | |
"body": "cde" | |
} | |
server.addResponse("sessionlog.json", request_header_0, response_header_0) | |
server.addResponse("sessionlog.json", request_header_1, response_header_1) | |
server.addResponse("sessionlog.json", request_header_2, response_header_2) | |
# Configure ATS server | |
ts.Disk.plugin_config.AddLines([ | |
'xdebug.so', | |
'regex_revalidate.so -d -c regex_revalidate.conf' | |
]) | |
regex_revalidate_conf_path = os.path.join(ts.Variables.CONFIGDIR, 'regex_revalidate.conf') | |
# Define first revistion for when trafficserver starts | |
ts.Disk.File(regex_revalidate_conf_path, typename="ats:config").AddLines([ | |
"# Empty\n" | |
]) | |
ts.Disk.remap_config.AddLine( | |
'map / http://127.0.0.1:{}'.format(server.Variables.Port) | |
) | |
# minimal configuration | |
ts.Disk.records_config.update({ | |
'proxy.config.diags.debug.enabled': 1, | |
'proxy.config.diags.debug.tags': 'regex_revalidate', | |
# 'proxy.config.diags.debug.enabled': 0, | |
'proxy.config.http.cache.http': 1, | |
'proxy.config.http.wait_for_cache': 1, | |
'proxy.config.http.insert_age_in_response': 0, | |
'proxy.config.http.response_via_str': 3, | |
'proxy.config.http.server_ports': '{}'.format(ts.Variables.port), | |
}) | |
## Test description: | |
# Load up cache, ensure fresh | |
# Create regex reval rule, config reload: | |
# ensure item is staled only once. | |
# Add a new rule, config reload: | |
# ensure item isn't restaled again, but rule still in effect. | |
# Test 1 - Load cache (miss) | |
tr = Test.AddTestRun("Cache miss") | |
tr.Processes.Default.StartBefore(server) | |
tr.Processes.Default.StartBefore(Test.Processes.ts, ready=1) | |
tr.Processes.Default.Command = 'curl -s -D - -v -H "x-debug: x-cache,via" -H "Host: www.example.com" http://127.0.0.1:{}/path1'.format(ts.Variables.port) | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.Streams.stdout = "gold/regex_reval-miss.gold" | |
tr.StillRunningAfter = ts | |
# Test 1a - Load cache (miss) for later test | |
tr = Test.AddTestRun("Cache miss") | |
tr.Processes.Default.Command = 'curl -s -D - -v -H "x-debug: x-cache,via" -H "Host: www.example.com" http://127.0.0.1:{}/path1a'.format(ts.Variables.port) | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.Streams.stdout = "gold/regex_reval-miss.gold" | |
tr.StillRunningAfter = ts | |
# Test 2 - Cache hit | |
tr = Test.AddTestRun("Cache hit fresh") | |
tr.Processes.Default.Command = 'curl -s -D - -v -H "x-debug: x-cache,via" -H "Host: www.example.com" http://127.0.0.1:{}/path1'.format(ts.Variables.port) | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.Streams.stdout = "gold/regex_reval-hit.gold" | |
tr.StillRunningAfter = ts | |
# Stage 3 - Reload new regex_revalidate | |
tr = Test.AddTestRun("Reload config") | |
# new file to load | |
tr.Disk.File(regex_revalidate_conf_path, typename="ats:config").AddLines([ | |
'path1 {}\n'.format(int(time.time()) + 600) | |
]) | |
tr.StillRunningAfter = ts | |
tr.StillRunningAfter = server | |
tr.Processes.Default.Command = 'traffic_ctl config reload' | |
# Need to copy over the environment so traffic_ctl knows where to find the unix domain socket | |
tr.Processes.Default.Env = ts.Env | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.TimeOut = 5 | |
tr.TimeOut = 5 | |
# Test 4 - Revalidate | |
tr = Test.AddTestRun("Revalidate stale") | |
tr.DelayStart = 5 | |
tr.Processes.Default.Command = 'curl -s -D - -v -H "x-debug: x-cache,via" -H "Host: www.example.com" http://127.0.0.1:{}/path1'.format(ts.Variables.port) | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.Streams.stdout = "gold/regex_reval-stale.gold" | |
tr.StillRunningAfter = ts | |
# Test 5 - Cache hit (again) | |
tr = Test.AddTestRun("Cache hit fresh") | |
tr.DelayStart = 5 | |
tr.Processes.Default.Command = 'curl -s -D - -v -H "x-debug: x-cache,via" -H "Host: www.example.com" http://127.0.0.1:{}/path1'.format(ts.Variables.port) | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.Streams.stdout = "gold/regex_reval-hit.gold" | |
tr.StillRunningAfter = ts | |
# Stage 6 - Reload new regex_revalidate | |
tr = Test.AddTestRun("Reload config") | |
# update config file | |
tr.Disk.File(regex_revalidate_conf_path, typename="ats:config").AddLines([ | |
'path2 {}\n'.format(int(time.time()) + 600) | |
]) | |
tr.StillRunningAfter = ts | |
tr.StillRunningAfter = server | |
tr.Processes.Default.Command = 'traffic_ctl config reload' | |
# Need to copy over the environment so traffic_ctl knows where to find the unix domain socket | |
tr.Processes.Default.Env = ts.Env | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.TimeOut = 5 | |
tr.TimeOut = 5 | |
# Test 7 - Cache hit (again) | |
tr = Test.AddTestRun("Cache hit fresh") | |
tr.DelayStart = 5 | |
tr.Processes.Default.Command = 'curl -s -D - -v -H "x-debug: x-cache,via" -H "Host: www.example.com" http://127.0.0.1:{}/path1'.format(ts.Variables.port) | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.Streams.stdout = "gold/regex_reval-hit.gold" | |
tr.StillRunningAfter = ts | |
# Test 7a - Cache stale (check rule is still loaded) | |
tr = Test.AddTestRun("Revalidate stale") | |
tr.Processes.Default.Command = 'curl -s -D - -v -H "x-debug: x-cache,via" -H "Host: www.example.com" http://127.0.0.1:{}/path1a'.format(ts.Variables.port) | |
tr.Processes.Default.ReturnCode = 0 | |
tr.Processes.Default.Streams.stdout = "gold/regex_reval-stale.gold" | |
tr.StillRunningAfter = ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment