This directory contains different tests for Apache Trafficserver. It is recommended that all test move to this common area under the correct location based on the type of test being added.
The current layout is:
gold_tests/ - contains all the TSQA v4 based tests that run on the Reusable Gold Testing System (AuTest) tools/ - contain programs used to help with testing.
In the future a directory called “unit/” will be added for adding unit tests based on some standardized testing system.
To help with easy running of the tests, there is a autest.sh and bootstrap.py file.
This file is a simple wrapper that will call the AuTest program in a python virtualenv. If the virtualenv is not setup it will try to install system. That will set up the Reusable Gold Testing System on most systems in a Python virtual environment. The wrapper add some basic options to the command to point to the location of the tests. Add --help for more details on options for running autest test system.
This script should try to install python35 or better on the system, and needed python packages for running the tests.
AuTest can be install manually instead of using the wrapper script. The advange of this is that it is often easier to debug issues with the testing system, or the tests. There are two ways this can be done.
When writting for the AuTest system please refer to the current documenation on the online wiki for general use of the system.
Autest allows for the creation of extension to help specilaize and simplify test writting for a given application domian. Minus API addition the extension code will check that python 3.5 or better is used. There is also a new command line argumented added:
--ats-bin < path to bin directory >
This command line argument will point to your build of ATS you want to test. At this time v6.0 or newer of Trafficserver should work.
This function will define a sandbox for an instance of trafficserver to run under. The function will return a AuTest process object that will have a number of files and variables define for making it easier to define a test.
The environment of the process will have a number of added environment variables to control trafficserver running the in the sandbox location correctly. This can be used to easily setup other commands that should run under same environment.
# Define default ATS ts=Test.MakeATSProcess("ts") # Call traffic_ctrl to set new generation tr=Test.AddTestRun() tr.Processes.Default.Command='traffic_ctl' tr.Processes.Default.ReturnCode=0 # set the environment for traffic_control to run in to be the same as the "ts" ATS instance tr.Processes.Default.Env=ts.Env
These are the current variable that are define dynamically
port - the ipv4 port to listen on portv6 - the ipv4 port to listen on manager_port - the manager port used. This is set even is select_port is False admin_port - the admin port used. This is set even is select_port is False
A number of file object are define to help with adding values to a given configuration value to for a test, or testing a value exists in a log file. File that are defined currently are:
Create a server
# don't set ports because a config file will set them ts1 = Test.MakeATSProcess("ts1",select_ports=False) ts1.Setup.ts.CopyConfig('config/records_8090.config','records.config')
Create a server and get the dynamic port value
# Define default ATS ts=Test.MakeATSProcess("ts") #first test is a miss for default tr=Test.AddTestRun() # get port for command from Variables tr.Processes.Default.Command='curl "http://127.0.0.1:{0}" --verbose'.format(ts.Variables.port)
Add value to a configuration file
# setup some config file for this server ts.Disk.records_config.update({ 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory 'proxy.config.http.cache.generation':-1, # Start with cache turned off 'proxy.config.config_update_interval_ms':1, }) ts.Disk.plugin_config.AddLine('xdebug.so') ts.Disk.remap_config.AddLines([ 'map /default/ http://127.0.0.1/ @plugin=generator.so', #line 2 'map /generation1/ http://127.0.0.1/' + ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=1' + ' @plugin=generator.so', #line 3 'map /generation2/ http://127.0.0.1/' + ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=2' + ' @plugin=generator.so' ])
This function copies a given configuration file the location of a given trafficserver sandbox used in a test. Given a test might have more than on trafficserver instance, it can be difficult to understand the correct location to copy to. This function will deal with the details correctly.
Copy a file over
ts1 = Test.MakeATSProcess("ts1",select_ports=False) # uses the setup object in the scope of the process object ts1.Setup.ts.CopyConfig('config/records_8090.config','records.config')
ts1 = Test.MakeATSProcess("ts1",select_ports=False) # uses the Setup in the global process via a variable passing Test.Setup.ts.CopyConfig('config/records_8090.config','records.config',ts1) # same as above, but uses the dynamic object model form Test.Setup.ts.CopyConfig('config/records_8090.config','records.config',Test.Processes.ts1)
This function returns a AuTest process object that launches the python-based microserver. Micro-Server is a mock server which responds to client http requests. Microserver needs to be setup for the tests that require an origin server behind ATS. The server reads a JSON-formatted data file that contains request headers and the corresponding response headers. Microserver responds with payload if the response header contains Content-Length or Transfer-Enconding specified.
This function adds the request header and response header to a file which is then read by the microserver to populate request-response map. The key-fields required for the header dictionary are ‘headers’, ‘timestamp’ and ‘body’.
#create the origin server process server=Test.MakeOriginServer("server") #define the request header and the desired response header request_header={"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""} #desired response form the origin server response_header={"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""} #addResponse adds the transaction to a file which is used by the server server.addResponse("sessionlog.json", request_header, response_header) #add remap rule to traffic server ts.Disk.remap_config.AddLine( 'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port) )