E2E tests for caching

This patch adds end to end tests to verify caching functionality.

Change-Id: I204b10e206f6092a76f3104b0e8d3956b3d8f1ce
This commit is contained in:
Malini Kamalambal 2015-07-23 16:15:46 -04:00
parent 0c475c246e
commit 0b8049ee4e
5 changed files with 225 additions and 109 deletions

View File

@ -59,7 +59,6 @@ class TestBase(fixtures.BaseTestFixture):
cls.test_config = config.TestConfig()
cls.poppy_config = config.PoppyConfig()
cls.cacherules_config = config.CacheRulesConfig()
cls.purge_config = config.PurgeRulesConfig()
if cls.poppy_config.project_id_in_url:

View File

@ -0,0 +1,185 @@
# Copyright (c) 2015 Rackspace, Inc.
#
# Licensed 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 time
from tests.endtoend import base
from tests.endtoend.utils import config
class TestCaching(base.TestBase):
@classmethod
def setUpClass(cls):
super(TestCaching, cls).setUpClass()
cls.caching_config = config.CachingConfig()
cls.default_origin = cls.caching_config.origin
cls.cacheable_endpoint = cls.caching_config.endpoint
cls.jpg_path = cls.caching_config.jpg_endpoint
cls.txt_path = cls.caching_config.txt_endpoint
cls.zip_path = cls.caching_config.zip_endpoint
cls.check_preconditions()
@classmethod
def check_preconditions(cls):
"""Ensure our environment meets our needs to ensure a valid test."""
origin = cls.http_client.get(
"http://" + cls.default_origin + cls.cacheable_endpoint)
assert origin.status_code == 200
jpg_origin = cls.http_client.get(
"http://" + cls.default_origin + cls.jpg_path)
assert jpg_origin.status_code == 200
txt_origin = cls.http_client.get(
"http://" + cls.default_origin + cls.txt_path)
assert txt_origin.status_code == 200
zip_origin = cls.http_client.get(
"http://" + cls.default_origin + cls.zip_path)
assert zip_origin.status_code == 200
def setUp(self):
super(TestCaching, self).setUp()
self.test_domain = "{0}.{1}".format(
base.random_string('test-caching'),
self.dns_config.test_domain)
self.service_name = base.random_string('E2E-CachingService')
self.cname_rec = []
def test_zero_caching(self):
domains = [{'domain': self.test_domain}]
origins = [{
"origin": self.default_origin,
"port": 80,
"ssl": False,
"rules": [{
"name": "default",
"request_url": "/*",
}],
"hostheadertype": "origin"
}]
caching = [
{"name": "default",
"ttl": 0,
"rules": [{"name": "default", "request_url": "/*"}]}]
resp = self.setup_service(
service_name=self.service_name,
domain_list=domains,
origin_list=origins,
caching_list=caching,
flavor_id=self.poppy_config.flavor)
self.service_location = resp.headers['location']
resp = self.poppy_client.get_service(location=self.service_location)
links = resp.json()['links']
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
rec = self.setup_cname(self.test_domain, access_url[0])
if rec:
self.cname_rec.append(rec[0])
cdn_url = 'http://' + self.test_domain + self.cacheable_endpoint
# Verify content is not cached
self.get_from_cdn_enabled_url(cdn_url=cdn_url, count=4)
self.assertCacheStatus(cdn_url=cdn_url,
status_list=['TCP_MISS', 'TCP_REFRESH_MISS'])
def test_cache_rules(self):
# Create a Poppy Service for the test website with cache rules
domain_list = [{"domain": self.test_domain}]
origin_list = [{"origin": self.default_origin,
"port": 80,
"ssl": False}]
jpg_ttl = self.caching_config.jpg_ttl
txt_ttl = self.caching_config.txt_ttl
zip_ttl = self.caching_config.zip_ttl
# Setup cache list using cache
caching_list = [
{"name": "jpg", "ttl": jpg_ttl,
"rules": [{"name": "jpg_rule", "request_url": self.jpg_path}]},
{"name": "txt", "ttl": txt_ttl,
"rules": [{"name": "txt_rule", "request_url": self.txt_path}]},
{"name": "zip", "ttl": zip_ttl,
"rules": [{"name": "zip_rule", "request_url": self.zip_path}]}]
self.service_name = base.random_string(prefix='testService-')
resp = self.setup_service(
service_name=self.service_name,
domain_list=domain_list,
origin_list=origin_list,
caching_list=caching_list,
flavor_id=self.poppy_config.flavor)
self.service_location = resp.headers['location']
resp = self.poppy_client.get_service(location=self.service_location)
links = resp.json()['links']
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
# Adds cname records corresponding to the test domains
rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
if rec:
self.cname_rec.append(rec[0])
origin_url = 'http://' + self.default_origin
cdn_url = 'http://' + self.test_domain
self.assertSameContent(origin_url=origin_url, cdn_url=cdn_url)
# Verify cdn hit on rule urls
cdn_jpg_url = cdn_url + self.jpg_path
self.get_from_cdn_enabled_url(cdn_url=cdn_jpg_url, count=2)
self.assertCacheStatus(cdn_url=cdn_jpg_url,
status_list=['TCP_HIT', 'TCP_MEM_HIT'])
cdn_txt_url = cdn_url + self.txt_path
self.get_from_cdn_enabled_url(cdn_url=cdn_txt_url, count=2)
self.assertCacheStatus(cdn_url=cdn_txt_url,
status_list=['TCP_HIT', 'TCP_MEM_HIT'])
cdn_zip_url = cdn_url + self.zip_path
self.get_from_cdn_enabled_url(cdn_url=cdn_zip_url, count=2)
self.assertCacheStatus(cdn_url=cdn_zip_url,
status_list=['TCP_HIT', 'TCP_MEM_HIT'])
time.sleep(max(jpg_ttl, zip_ttl, txt_ttl))
# Verify that content in cache is stale/removed after the ttl expires
self.assertCacheStatus(
cdn_url=cdn_jpg_url,
status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
self.assertCacheStatus(
cdn_url=cdn_txt_url,
status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
self.assertCacheStatus(
cdn_url=cdn_zip_url,
status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
def tearDown(self):
self.poppy_client.delete_service(location=self.service_location)
for record in self.cname_rec:
self.dns_client.delete_record(record)
super(TestCaching, self).tearDown()

View File

@ -128,86 +128,6 @@ class TestWebsiteCDN(base.TestBase):
print(wpt_result_1)
print(wpt_result_2)
def test_cache_rules(self):
# Create a Poppy Service for the test website with cache rules
domain_list = [{"domain": self.test_domain}]
origin_list = [{"origin": self.origin,
"port": 80,
"ssl": False}]
rule1 = self.cacherules_config.cache_rule1
ttlrule1 = self.cacherules_config.ttl_rule1
rule2 = self.cacherules_config.cache_rule2
ttlrule2 = self.cacherules_config.ttl_rule2
rule3 = self.cacherules_config.cache_rule3
ttlrule3 = self.cacherules_config.ttl_rule3
# Setup cache list using cache
caching_list = [{"name": "images", "ttl": ttlrule1, "rules":
[{"name": "image_rule",
"request_url": rule1}]},
{"name": "images", "ttl": ttlrule2, "rules":
[{"name": "css_rule",
"request_url": rule2}]},
{"name": "images", "ttl": ttlrule3, "rules":
[{"name": "js_rule",
"request_url": rule3}]}]
self.service_name = base.random_string(prefix='testService-')
resp = self.setup_service(
service_name=self.service_name,
domain_list=domain_list,
origin_list=origin_list,
caching_list=caching_list,
flavor_id=self.poppy_config.flavor)
self.service_location = resp.headers['location']
resp = self.poppy_client.get_service(location=self.service_location)
links = resp.json()['links']
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
# Adds cname records corresponding to the test domains
rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
if rec:
self.cname_rec.append(rec[0])
origin_url = 'http://' + self.origin
cdn_enabled_url = 'http://' + self.test_domain
self.assertSameContent(origin_url=origin_url,
cdn_url=cdn_enabled_url)
# Verify cdn hit on rule urls
self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule1, count=2)
self.assertCacheStatus(cdn_url=cdn_enabled_url + rule1,
status_list=['TCP_HIT', 'TCP_MEM_HIT'])
self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule2, count=2)
self.assertCacheStatus(cdn_url=cdn_enabled_url + rule2,
status_list=['TCP_HIT', 'TCP_MEM_HIT'])
self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule3, count=2)
self.assertCacheStatus(cdn_url=cdn_enabled_url + rule3,
status_list=['TCP_HIT', 'TCP_MEM_HIT'])
time.sleep(max(ttlrule1, ttlrule2, ttlrule3))
# Verify that content in cache is stale/removed after the ttl expires
self.assertCacheStatus(
cdn_url=cdn_enabled_url + rule1,
status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
self.assertCacheStatus(
cdn_url=cdn_enabled_url + rule2,
status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
self.assertCacheStatus(
cdn_url=cdn_enabled_url + rule3,
status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
def test_purge(self):
# Create a Poppy Service for the test website

View File

@ -181,39 +181,49 @@ class DNSConfig(data_interfaces.ConfigSectionInterface):
return int(self.get('cdn_provider_dns_sleep'))
class CacheRulesConfig(data_interfaces.ConfigSectionInterface):
"""Defines the cacherules config values."""
SECTION_NAME = 'cacherules'
class CachingConfig(data_interfaces.ConfigSectionInterface):
"""Defines the config values for caching tests."""
SECTION_NAME = 'caching'
@property
def cache_rule1(self):
"""Cache Rule 1."""
return self.get('cache_path_rule1')
def origin(self):
"""Default Origin for Caching Tests."""
return self.get('default_origin')
@property
def ttl_rule1(self):
"""TTL for Cache Rule 1."""
return int(self.get('ttl_rule1'))
def endpoint(self):
"""Path to cacheable content."""
return self.get('cache_path')
@property
def cache_rule2(self):
"""Cache Rule 2."""
return self.get('cache_path_rule2')
def jpg_endpoint(self):
"""Path to jpg content."""
return self.get('jpg_path')
@property
def ttl_rule2(self):
"""TTL for Cache Rule 2."""
return int(self.get('ttl_rule2'))
def jpg_ttl(self):
"""TTL for jpg content."""
return int(self.get('jpg_ttl'))
@property
def cache_rule3(self):
"""Cache Rule 3."""
return self.get('cache_path_rule3')
def txt_endpoint(self):
"""Path to txt content."""
return self.get('txt_path')
@property
def ttl_rule3(self):
"""TTL for Cache Rule 3."""
return int(self.get('ttl_rule3'))
def txt_ttl(self):
"""TTL for txt content."""
return int(self.get('txt_ttl'))
@property
def zip_endpoint(self):
"""Path to zip content."""
return self.get('zip_path')
@property
def zip_ttl(self):
"""TTL for zip content."""
return int(self.get('zip_ttl'))
class MultipleOriginConfig(data_interfaces.ConfigSectionInterface):

View File

@ -57,13 +57,15 @@ api_key={api key for webpagetest instance}
# GET http://www.webpagetest.org/getLocations.php - Use <id> tag
test_locations=Wellington:Chrome, Indore:Firefox, Stockholm:Safari, Dulles:Firefox, Miami:Chrome
[cacherules]
cache_path_rule1=/static/images/products/image2_320x150.jpg
ttl_rule1=10
cache_path_rule2={cache_rule2}
ttl_rule2=20
cache_path_rule3={cache_rule3}
ttl_rule3=30
[caching]
default_origin=1.2.3.4
cache_path=/test/expires/expires.jpg
jpg_path=/test/camera.jpg
jpg_ttl=10
txt_path=/test/text.txt
txt_ttl=10
zip_path=/test/line.zip
zip_ttl=10
[purgetime]
# Time to wait for purging content to complete