Merge lp:~gary/launchpad/bug586466 into lp:launchpad

Proposed by Gary Poster
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 10982
Proposed branch: lp:~gary/launchpad/bug586466
Merge into: lp:launchpad
Diff against target: 161 lines (+46/-14)
4 files modified
lib/lp/registry/browser/tests/milestone-views.txt (+15/-6)
lib/lp/registry/templates/milestone-index.pt (+0/-2)
lib/lp/services/memcache/doc/tales-cache.txt (+22/-2)
lib/lp/services/memcache/tales.py (+9/-4)
To merge this branch: bzr merge lp:~gary/launchpad/bug586466
Reviewer Review Type Date Requested Status
Curtis Hovey (community) Approve
Review via email: mp+27174@code.launchpad.net

Commit message

Provide tal memcached testing convenience

Description of the change

The basic change here was already approved by sinzui on IRC. However, I had to change the test for the tal feature. I'd like a re-review to make sure the change I made to underwear couldn't be done better.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

This is a nice fix. Thanks for doing this. Really!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/tests/milestone-views.txt'
2--- lib/lp/registry/browser/tests/milestone-views.txt 2010-05-27 04:10:17 +0000
3+++ lib/lp/registry/browser/tests/milestone-views.txt 2010-06-09 16:13:28 +0000
4@@ -306,22 +306,31 @@
5
6 Active milestones cache bugtasks for 10 minutes.
7
8+ >>> from canonical.testing.layers import MemcachedLayer
9+ >>> MemcachedLayer.purge()
10 >>> cached_milestone = factory.makeMilestone(
11 ... 'cache-test', productseries=series)
12 >>> cached_bugtask = factory.makeBugTask(target=cached_milestone.product)
13 >>> cached_bugtask.milestone = cached_milestone
14 >>> view = create_view(cached_milestone, '+index', principal=person)
15- >>> content = view.render()
16- >>> 'milestone_bugtasks cache:private 10 minute' in content
17- True
18+ >>> 'Cache hit' in view.render()
19+ False
20+ >>> print create_view(
21+ ... cached_milestone, '+index', principal=person).render()
22+ <...<!-- Cache hit: memcache expression (private, 10 minute) -->
23+ <table class="listing sortable" id="milestone_bugtasks">...
24
25 Inactive milestones cache bugtasks for 3 hours.
26
27+ >>> MemcachedLayer.purge()
28 >>> cached_milestone.active = False
29 >>> view = create_view(cached_milestone, '+index', principal=person)
30- >>> content = view.render()
31- >>> 'milestone_bugtasks cache:private 3 hour' in content
32- True
33+ >>> 'Cache hit' in view.render()
34+ False
35+ >>> print create_view(
36+ ... cached_milestone, '+index', principal=person).render()
37+ <...<!-- Cache hit: memcache expression (private, 3 hour) -->
38+ <table class="listing sortable" id="milestone_bugtasks">...
39
40
41 ProjectGroup milestones
42
43=== modified file 'lib/lp/registry/templates/milestone-index.pt'
44--- lib/lp/registry/templates/milestone-index.pt 2010-05-27 04:10:17 +0000
45+++ lib/lp/registry/templates/milestone-index.pt 2010-06-09 16:13:28 +0000
46@@ -268,13 +268,11 @@
47 <tal:has_bugtasks condition="bugtasks">
48 <tal:active content="cache:private, 10 minute"
49 condition="view/milestone/active">
50- <!-- milestone_bugtasks cache:private 10 minute -->
51 <tal:milestone-bugtasks
52 metal:use-macro="context/@@+milestone-macros/milestone_bugtasks" />
53 </tal:active>
54 <tal:inactive content="cache:private, 3 hour"
55 condition="not: view/milestone/active">
56- <!-- milestone_bugtasks cache:private 3 hour -->
57 <tal:milestone-bugtasks
58 metal:use-macro="context/@@+milestone-macros/milestone_bugtasks" />
59 </tal:inactive>
60
61=== modified file 'lib/lp/services/memcache/doc/tales-cache.txt'
62--- lib/lp/services/memcache/doc/tales-cache.txt 2010-03-31 06:39:03 +0000
63+++ lib/lp/services/memcache/doc/tales-cache.txt 2010-06-09 16:13:28 +0000
64@@ -26,10 +26,14 @@
65 cause this template to render differently.
66
67 >>> print template(param='second')
68- <div>
69+ <div><!-- Cache hit: memcache expression (public) -->
70 <span>first</span>
71- </div>
72+ <!-- End cache hit: memcache expression (public) --></div>
73
74+We also see some comments showing that we had a cache hit, and what the
75+configuration was for it ("public"). These comments are only present
76+when Launchpad's config is not configured as edge or production (``is_edge``
77+or ``is_lpnet``, respectively).
78
79 If we clear the cache, it will be rendered as expected.
80
81@@ -141,7 +145,9 @@
82
83 >>> login('foo.bar@canonical.com')
84 >>> print template(username='Foo Bar')
85+ <!-- Cache hit: memcache expression (public) -->
86 Public: Anonymous
87+ <!-- End cache hit: memcache expression (public) -->
88 Private: Foo Bar
89 Anonymous: Foo Bar
90 Authenticated: Foo Bar
91@@ -151,10 +157,14 @@
92
93 >>> login('test@canonical.com')
94 >>> print template(username='Test')
95+ <!-- Cache hit: memcache expression (public) -->
96 Public: Anonymous
97+ <!-- End cache hit: memcache expression (public) -->
98 Private: Test
99 Anonymous: Test
100+ <!-- Cache hit: memcache expression (authenticated) -->
101 Authenticated: Foo Bar
102+ <!-- End cache hit: memcache expression (authenticated) -->
103
104
105 Nesting & Loops
106@@ -163,6 +173,14 @@
107 Cached chunks can contain other cached chunks, useful for specifying
108 different timeouts of different visibilities.
109
110+We will disable the cache hit comments by claiming to be in production.
111+
112+ >>> from canonical.config import config
113+ >>> original_instance_name = config.instance_name
114+ >>> config.push('is_production', """
115+ ... [launchpad]
116+ ... is_lpnet: True
117+ ... """)
118 >>> template = TestPageTemplate(dedent("""\
119 ... <body tal:content="cache:private,25 seconds" tal:omit-tag="">
120 ... This bit is private to <span tal:replace="username" />
121@@ -291,3 +309,5 @@
122 Mutated comment
123 </body>
124
125+ >>> ignore = config.pop('is_production')
126+
127
128=== modified file 'lib/lp/services/memcache/tales.py'
129--- lib/lp/services/memcache/tales.py 2010-03-31 06:39:03 +0000
130+++ lib/lp/services/memcache/tales.py 2010-06-09 16:13:28 +0000
131@@ -225,7 +225,7 @@
132
133 if cached_chunk is None:
134 logging.debug("Memcache miss for %s", key)
135- return MemcacheMiss(key, self.max_age)
136+ return MemcacheMiss(key, self)
137 else:
138 logging.debug("Memcache hit for %s", key)
139 return MemcacheHit(cached_chunk)
140@@ -244,13 +244,18 @@
141 tag contents and invokes this callback, which will store the
142 result in memcache against the key calculated by the MemcacheExpr.
143 """
144- def __init__(self, key, max_age):
145+ def __init__(self, key, memcache_expr):
146 self._key = key
147- self._max_age = max_age
148+ self._memcache_expr = memcache_expr
149
150 def __call__(self, value):
151+ if not config.launchpad.is_lpnet and not config.launchpad.is_edge:
152+ # For debugging and testing purposes, prepend a description of
153+ # the memcache expression used to the stored value.
154+ value = "<!-- Cache hit: %s -->%s<!-- End cache hit: %s -->" % (
155+ self._memcache_expr, value, self._memcache_expr)
156 if getUtility(IMemcacheClient).set(
157- self._key, value, self._max_age):
158+ self._key, value, self._memcache_expr.max_age):
159 logging.debug("Memcache set succeeded for %s", self._key)
160 else:
161 logging.warn("Memcache set failed for %s", self._key)