Merge lp:~kfader/mvhub/pages.t-too-slow into lp:mvhub
- pages.t-too-slow
- Merge into trunk_2format
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 512 | ||||||||
Proposed branch: | lp:~kfader/mvhub/pages.t-too-slow | ||||||||
Merge into: | lp:mvhub | ||||||||
Diff against target: |
448 lines (+99/-33) 6 files modified
app-mvhub/t/bugs/admin_logout_bug.t (+2/-2) app-mvhub/t/bugs/categorize_link_missing_when_agency_login.t (+6/-8) app-mvhub/t/bugs/ql_display_agency_home_interaction.t (+4/-3) app-mvhub/t/bugs/ql_works_after_admin_login.t (+3/-3) app-mvhub/t/mech/pages.t (+53/-17) lib-mvhub/t/lib/TestHelper.pm (+31/-0) |
||||||||
To merge this branch: | bzr merge lp:~kfader/mvhub/pages.t-too-slow | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dan MacNeil | Approve | ||
Review via email: mp+37314@code.launchpad.net |
Commit message
Description of the change
See commit log.
Dan MacNeil (omacneil) wrote : | # |
A few problems:
You take out all the:
$mech->get( $$page{url}
..so the tests are all invalid, they test a mech object that doesn't contain a page. We save a lot of time by not traveling over the network to fetch a web page, but we cant test the links or the validity of the html if we don't have the page.
perl objects are references, roughly akin to pointers.
So you assign a pointer to the same thing to each mech object in the @pages array.
if a is pointer that points to address 33558 and you say a=b then b also points to address 33558
To help see these problems paste this code into main at some point.
foreach my $page_href (@total_pages){
my $mech=$
print "mech object is:",$$
}
;
exit 0;
One patial solution would be to create a new() object in your add_mech_objects() sub and to call $mech->get( $$page{url} in that sub.
- 504. By Keith Fader
-
Modified these files to initialize mech objects correctly. TestHelper will now grab the mech objects out of the pages hash, for consistency.
- 505. By Keith Fader
-
Fixed add_mech_objects to initialize new mech object each time. Modified TestHelper to use cached mech objects for consistency
Dan MacNeil (omacneil) wrote : | # |
39 + #TestHelper:
On general principles, you shouldn't submit commented out code for merge request.
It adds noise, With version control you can get it back
Dan MacNeil (omacneil) wrote : | # |
tests fail.
Before submitting merge request, all should pass
run them with:
mv_prove -r app-mvhub/t lib-mvhub/t
app-mvhub/
...and anything that uses TestHelper:
sub routine was in a library for a reason...
Need to either add caching to routine (quick little & little ugly) or change every test file that uses it.
- 506. By Keith Fader
-
Reverted TestHelper.pm. There was no need to change it in the first
place. Ran perltidy on pages.t. All tests pass, speed is good. - 507. By Keith Fader
-
Changes from two weeks ago.
- 508. By Keith Fader
-
merged trunk
Dan MacNeil (omacneil) wrote : | # |
in pages.t
sub add_mech_objects {
... is never called.
Dan MacNeil (omacneil) wrote : | # |
8 - my $mech = shift or die 'pages_get_ok() missing param: $mech';
9 - my @pages = @_ or die 'pages_get_ok() missing param: @pages';
10 + my $mech = shift or die 'run_tests() missing param: $mech';
11 + my @pages = @_ or die 'run_tests() missing param: @pages';
Good in passing fix, closer to perfect would be to mention in commit log
Dan MacNeil (omacneil) wrote : | # |
Otherwise good.
Dan MacNeil (omacneil) wrote : | # |
merge fairy will remove the kruft.
Preview Diff
1 | === modified file 'app-mvhub/t/bugs/admin_logout_bug.t' |
2 | --- app-mvhub/t/bugs/admin_logout_bug.t 2010-09-27 13:28:16 +0000 |
3 | +++ app-mvhub/t/bugs/admin_logout_bug.t 2010-10-29 19:42:40 +0000 |
4 | @@ -45,8 +45,8 @@ |
5 | use Test::Harness; |
6 | |
7 | sub run_tests { |
8 | - my $mech = shift or die 'pages_get_ok() missing param: $mech'; |
9 | - my @pages = @_ or die 'pages_get_ok() missing param: @pages'; |
10 | + my $mech = shift or die 'run_tests() missing param: $mech'; |
11 | + my @pages = @_ or die 'run_tests() missing param: @pages'; |
12 | |
13 | foreach my $page (@pages) { |
14 | $mech->add_header( Authorization => $$page{auth} ) |
15 | |
16 | === modified file 'app-mvhub/t/bugs/categorize_link_missing_when_agency_login.t' |
17 | --- app-mvhub/t/bugs/categorize_link_missing_when_agency_login.t 2010-09-27 13:28:16 +0000 |
18 | +++ app-mvhub/t/bugs/categorize_link_missing_when_agency_login.t 2010-10-29 19:42:40 +0000 |
19 | @@ -22,11 +22,9 @@ |
20 | my $number_of_tests = ( ( scalar @pages ) * 4 ); |
21 | |
22 | plan tests => $number_of_tests; |
23 | - my $mech = Test::WWW::Mechanize->new(); |
24 | - $mech->default_header( Authorization => TestHelper::create_temp_auth() ); |
25 | |
26 | - TestHelper::pages_get_ok( $mech, @pages ); |
27 | - check_for_categorize_link( $mech, @pages ); |
28 | + TestHelper::pages_add_ok(@pages); |
29 | + check_for_categorize_link(@pages); |
30 | } # main |
31 | |
32 | sub init_pages { |
33 | @@ -45,17 +43,17 @@ |
34 | "Agency Account Home Page - North Shore Community Action Programs", |
35 | 'tests_to_skip' => '', |
36 | 'todo_reason' => 'Need to fix diplay agency home page', |
37 | + 'mech' => undef, |
38 | }, |
39 | ); |
40 | return @pages; |
41 | } |
42 | |
43 | sub check_for_categorize_link { |
44 | - my $mech = shift or die 'page_links_ok() missing param: $mech'; |
45 | - my @pages = @_ or die 'page_links_ok() missing param: @pages'; |
46 | - |
47 | + my @pages = @_ or die 'page_links_ok() missing param: @pages'; |
48 | + my $mech; |
49 | foreach my $page (@pages) { |
50 | - $mech->get( $$page{url} ); |
51 | + $mech = $$page{mech}; |
52 | ok( $mech->find_link( text => 'categorize' ), |
53 | "Found categorize link on the page" |
54 | ); |
55 | |
56 | === modified file 'app-mvhub/t/bugs/ql_display_agency_home_interaction.t' |
57 | --- app-mvhub/t/bugs/ql_display_agency_home_interaction.t 2010-09-27 13:28:16 +0000 |
58 | +++ app-mvhub/t/bugs/ql_display_agency_home_interaction.t 2010-10-29 19:42:40 +0000 |
59 | @@ -22,10 +22,8 @@ |
60 | my $number_of_tests = ( ( scalar @pages ) * 3 ); |
61 | |
62 | plan tests => $number_of_tests; |
63 | - my $mech = Test::WWW::Mechanize->new(); |
64 | - $mech->default_header( Authorization => TestHelper::create_temp_auth() ); |
65 | |
66 | - TestHelper::pages_get_ok( $mech, @pages ); |
67 | + TestHelper::pages_add_ok(@pages); |
68 | |
69 | } # main |
70 | |
71 | @@ -44,6 +42,7 @@ |
72 | "Agency Account Home Page - North Shore Community Action Programs", |
73 | 'tests_to_skip' => '', |
74 | 'skip_reason' => '', |
75 | + 'mech' => undef |
76 | }, |
77 | |
78 | { 'url' => |
79 | @@ -51,6 +50,7 @@ |
80 | 'expected_content' => "You must log in to access this page", |
81 | 'tests_to_skip' => '', |
82 | 'skip_reason' => '', |
83 | + 'mech' => undef |
84 | }, |
85 | |
86 | { 'url' => |
87 | @@ -58,6 +58,7 @@ |
88 | 'expected_content' => "Transitions", |
89 | 'tests_to_skip' => '', |
90 | 'skip_reason' => '', |
91 | + 'mech' => undef |
92 | }, |
93 | |
94 | ); |
95 | |
96 | === modified file 'app-mvhub/t/bugs/ql_works_after_admin_login.t' |
97 | --- app-mvhub/t/bugs/ql_works_after_admin_login.t 2010-09-13 00:58:44 +0000 |
98 | +++ app-mvhub/t/bugs/ql_works_after_admin_login.t 2010-10-29 19:42:40 +0000 |
99 | @@ -25,10 +25,8 @@ |
100 | my $number_of_tests = ( ( scalar @pages ) * 3 ); |
101 | |
102 | plan tests => $number_of_tests; |
103 | - my $mech = Test::WWW::Mechanize->new(); |
104 | - $mech->default_header( Authorization => TestHelper::create_temp_auth() ); |
105 | |
106 | - TestHelper::pages_get_ok( $mech, @pages ); |
107 | + TestHelper::pages_add_ok(@pages); |
108 | } # main |
109 | |
110 | sub init_pages { |
111 | @@ -43,6 +41,7 @@ |
112 | 'expected_content' => "Welcome to the Administrative Home Page", |
113 | 'tests_to_skip' => '', |
114 | 'skip_reason' => '', |
115 | + 'mech' => undef, |
116 | }, |
117 | { 'url' => |
118 | "http://$host/cgi-bin/mvhub/agency.pl?rm=ql&aid=$agency_id&qlid=$quick_login_id", |
119 | @@ -50,6 +49,7 @@ |
120 | "Agency Account Home Page - North Shore Community Action Programs", |
121 | 'tests_to_skip' => '', |
122 | 'skip_reason' => '', |
123 | + 'mech' => undef, |
124 | }, |
125 | |
126 | ); |
127 | |
128 | === modified file 'app-mvhub/t/mech/pages.t' |
129 | --- app-mvhub/t/mech/pages.t 2010-09-13 00:58:44 +0000 |
130 | +++ app-mvhub/t/mech/pages.t 2010-10-29 19:42:40 +0000 |
131 | @@ -14,6 +14,7 @@ |
132 | |
133 | { #main |
134 | my $host = TestHelper::get_test_website_name('mvh'); |
135 | + my $mech = Test::WWW::Mechanize->new(); |
136 | |
137 | my @mvh_pages_from_both = init_pages_for_both($host); |
138 | my @pages_for_mvh = init_pages_for_mvh_only($host); |
139 | @@ -33,17 +34,15 @@ |
140 | ); |
141 | |
142 | my $NUMBER_OF_TESTS_PER_PAGE = 6; |
143 | + |
144 | my $number_of_tests |
145 | = ( ( scalar @total_pages ) * $NUMBER_OF_TESTS_PER_PAGE ); |
146 | - |
147 | plan tests => $number_of_tests; |
148 | - my $mech = Test::WWW::Mechanize->new(); |
149 | - $mech->default_header( Authorization => TestHelper::create_temp_auth() ); |
150 | |
151 | - TestHelper::pages_get_ok( $mech, @total_pages ); |
152 | - pages_links_ok( $mech, @total_pages ); |
153 | - pages_lint_ok( $mech, @total_pages ); |
154 | - pages_html_tidy_ok( $mech, @total_pages ); |
155 | + TestHelper::pages_add_ok(@total_pages); |
156 | + pages_links_ok(@total_pages); |
157 | + pages_lint_ok(@total_pages); |
158 | + pages_html_tidy_ok(@total_pages); |
159 | |
160 | } #main |
161 | |
162 | @@ -55,62 +54,74 @@ |
163 | 'expected_content' => " Search for Social Services", |
164 | 'tests_to_skip' => 'tidy lint link get', |
165 | 'skip_reason' => 'dan 2008-02-06 testing ability to skip', |
166 | + 'mech' => undef, |
167 | }, |
168 | { 'url' => "http://$host", |
169 | 'expected_content' => "Search for Social Services", |
170 | 'tests_to_skip' => '', |
171 | 'skip_reason' => '', |
172 | + 'mech' => undef, |
173 | }, |
174 | { 'url' => "http://$host/html/about.shtml", |
175 | 'expected_content' => "Our Purpose", |
176 | 'tests_to_skip' => '', |
177 | 'skip_reason' => '', |
178 | + 'mech' => undef, |
179 | }, |
180 | { 'url' => "http://$host/html/help.shtml", |
181 | 'expected_content' => "Agency Account Help", |
182 | 'tests_to_skip' => '', |
183 | 'skip_reason' => '', |
184 | + 'mech' => undef, |
185 | }, |
186 | { 'url' => "http://$host/html/register.shtml", |
187 | 'expected_content' => "Why register your agency", |
188 | 'tests_to_skip' => '', |
189 | 'skip_reason' => '', |
190 | + 'mech' => undef, |
191 | }, |
192 | { 'url' => "http://$host/reports", |
193 | 'expected_content' => "PDF Reports", |
194 | 'tests_to_skip' => '', |
195 | 'skip_reason' => '', |
196 | + 'mech' => undef, |
197 | }, |
198 | { 'url' => "http://$host/reports/", |
199 | 'expected_content' => "PDF Reports", |
200 | 'tests_to_skip' => '', |
201 | 'skip_reason' => '', |
202 | + 'mech' => undef, |
203 | }, |
204 | |
205 | { 'url' => "http://$host/cgi-bin/mvhub/agency_form.pl", |
206 | 'expected_content' => "Password", |
207 | 'tests_to_skip' => '', |
208 | 'skip_reason' => '', |
209 | + 'mech' => undef, |
210 | }, |
211 | { 'url' => "http://$host/cgi-bin/mvhub/guide.pl?rm=browse_headings", |
212 | 'expected_content' => "Arts/Culture/Entertainment", |
213 | 'tests_to_skip' => '', |
214 | 'skip_reason' => '', |
215 | + 'mech' => undef, |
216 | }, |
217 | { 'url' => "http://$host/cgi-bin/mvhub/admin/admin_reports.pl", |
218 | 'expected_content' => "Administrative Reports", |
219 | 'tests_to_skip' => '', |
220 | 'skip_reason' => '', |
221 | + 'mech' => undef, |
222 | }, |
223 | { 'url' => "http://$host/cgi-bin/mvhub/admin/admin.pl", |
224 | 'expected_content' => "Add a New Agency", |
225 | 'tests_to_skip' => '', |
226 | 'skip_reason' => '', |
227 | + 'mech' => undef, |
228 | }, |
229 | { 'url' => "http://$host/cgi-bin/mvhub/logout.pl", |
230 | 'expected_content' => "You have been logged out", |
231 | 'tests_to_skip' => '', |
232 | 'skip_reason' => '', |
233 | + 'mech' => undef, |
234 | }, |
235 | { 'url' => |
236 | "http://$host/cgi-bin/mvhub/agency.pl?rm=ql&aid=00&qlid=00", |
237 | @@ -118,12 +129,14 @@ |
238 | "Invalid quick log-in ID, please log in manually", |
239 | 'tests_to_skip' => '', |
240 | 'skip_reason' => '', |
241 | + 'mech' => undef, |
242 | }, |
243 | { 'url' => "http://$host/cgi-bin/mvhub/agency.pl?rm=ql&id=00", |
244 | 'expected_content' => |
245 | "You used an old login URL that is no longer valid", |
246 | 'tests_to_skip' => '', |
247 | 'skip_reason' => '', |
248 | + 'mech' => undef, |
249 | }, |
250 | ); |
251 | return @pages; |
252 | @@ -139,6 +152,7 @@ |
253 | 'expected_content' => "You must log in to access this page", |
254 | 'tests_to_skip' => '', |
255 | 'skip_reason' => '', |
256 | + 'mech' => undef, |
257 | }, |
258 | { 'url' => |
259 | "http://$host//cgi-bin/mvhub/guide.pl?rm=show_agency&agency_id=100088", |
260 | @@ -146,23 +160,27 @@ |
261 | 'tests_to_skip' => 'tidy lint', |
262 | 'skip_reason' => |
263 | 'dan 2008-02-06 record uses smart quotes we dont strip ', |
264 | + 'mech' => undef, |
265 | }, |
266 | { 'url' => |
267 | "http://$host/cgi-bin/mvhub/guide.pl?rm=show_agency&agency_id=101342", |
268 | 'expected_content' => "(The CSL)", |
269 | 'tests_to_skip' => '', |
270 | 'skip_reason' => '', |
271 | + 'mech' => undef, |
272 | }, |
273 | { 'url' => |
274 | "http://$host/cgi-bin/mvhub/guide.pl?rm=show_program&program_id=503916", |
275 | 'expected_content' => "Community Software Lab", |
276 | 'tests_to_skip' => '', |
277 | 'skip_reason' => '', |
278 | + 'mech' => undef, |
279 | }, |
280 | { 'url' => "http://$host/html/reports.shtml", |
281 | 'expected_content' => "formatted for printing", |
282 | 'tests_to_skip' => 'link', |
283 | 'skip_reason' => 'dan 2008-02-06 link to pdf not implemented', |
284 | + 'mech' => undef, |
285 | }, |
286 | { 'url' => |
287 | "http://$host/cgi-bin/mvhub/guide.pl?rm=show_program_results&category_id=804796", |
288 | @@ -170,6 +188,7 @@ |
289 | "programs related to: Visual Arts Classes, Youth/Teen", |
290 | 'tests_to_skip' => '', |
291 | 'skip_reason' => '', |
292 | + 'mech' => undef, |
293 | }, |
294 | ); |
295 | } |
296 | @@ -189,6 +208,7 @@ |
297 | 'expected_content' => "You must log in to access this page", |
298 | 'tests_to_skip' => '', |
299 | 'skip_reason' => '', |
300 | + 'mech' => undef, |
301 | }, |
302 | { 'url' => |
303 | "http://$host//cgi-bin/mvhub/guide.pl?rm=show_agency&agency_id=103531", |
304 | @@ -196,18 +216,21 @@ |
305 | 'tests_to_skip' => 'tidy lint', |
306 | 'skip_reason' => |
307 | 'dan 2008-02-06 record uses smart quotes we dont strip ', |
308 | + 'mech' => undef, |
309 | }, |
310 | { 'url' => |
311 | "http://$host/cgi-bin/mvhub/guide.pl?rm=show_agency&agency_id=103542", |
312 | 'expected_content' => "Law Center of Massachusetts", |
313 | 'tests_to_skip' => '', |
314 | 'skip_reason' => '', |
315 | + 'mech' => undef, |
316 | }, |
317 | { 'url' => |
318 | "http://$host/cgi-bin/mvhub/guide.pl?rm=show_program&program_id=509515", |
319 | 'expected_content' => "(NSCAP)", |
320 | 'tests_to_skip' => '', |
321 | 'skip_reason' => '', |
322 | + 'mech' => undef, |
323 | }, |
324 | { 'url' => |
325 | "http://$host/cgi-bin/mvhub/guide.pl?rm=show_program_results&category_id=801584", |
326 | @@ -215,12 +238,14 @@ |
327 | "programs related to: Adult Basic Education", |
328 | 'tests_to_skip' => '', |
329 | 'skip_reason' => '', |
330 | + 'mech' => undef, |
331 | }, |
332 | { 'url' => "http://$host/$agency_id/$quick_login_id", |
333 | 'expected_content' => |
334 | "Agency Account Home Page - North Shore Community Action Programs, Inc.", |
335 | 'tests_to_skip' => '', |
336 | 'skip_reason' => '', |
337 | + 'mech' => undef, |
338 | }, |
339 | { 'url' => |
340 | "http://$host/cgi-bin/mvhub/agency.pl?rm=ql&aid=$agency_id&qlid=$quick_login_id", |
341 | @@ -228,18 +253,31 @@ |
342 | "Agency Account Home Page - North Shore Community Action Programs, Inc.", |
343 | 'tests_to_skip' => '', |
344 | 'skip_reason' => '', |
345 | + 'mech' => undef, |
346 | }, |
347 | ); |
348 | } |
349 | |
350 | +sub add_mech_objects { |
351 | + my @pages = @_ or die 'add_mech_objects() missing param: @pages'; |
352 | + |
353 | + foreach my $page (@pages) { |
354 | + my $mech = Test::WWW::Mechanize->new(); |
355 | + $mech->default_header( |
356 | + Authorization => TestHelper::create_temp_auth() ); |
357 | + $mech->get( $$page{url} ); |
358 | + $$page{mech} = $mech; |
359 | + } |
360 | + @pages; |
361 | +} |
362 | + |
363 | sub pages_links_ok { |
364 | - my $mech = shift or die 'page_links_ok() missing param: $mech'; |
365 | - my @pages = @_ or die 'page_links_ok() missing param: @pages'; |
366 | - |
367 | + my @pages = @_ or die 'page_links_ok() missing param: @pages'; |
368 | + my $mech = ''; |
369 | PAGES: |
370 | foreach my $page (@pages) { |
371 | SKIP: { |
372 | - $mech->get( $$page{url} ); |
373 | + $mech = $$page{mech}; |
374 | if ( $$page{tests_to_skip} =~ 'link' ) { |
375 | skip "$$page{url} $$page{skip_reason}", 1; |
376 | next PAGES; |
377 | @@ -296,12 +334,11 @@ |
378 | } |
379 | |
380 | sub pages_lint_ok { |
381 | - my $mech = shift or die 'page_lint_ok() missing param: $mech'; |
382 | - my @pages = @_ or die 'page_lint_ok() missing param: @pages'; |
383 | + my @pages = @_ or die 'page_lint_ok() missing param: @pages'; |
384 | |
385 | foreach my $page (@pages) { |
386 | SKIP: { |
387 | - $mech->get( $$page{url} ); |
388 | + my $mech = $$page{mech}; |
389 | skip $$page{skip_reason}, 1 |
390 | if $$page{tests_to_skip} =~ 'lint'; |
391 | $mech->html_lint_ok("Lint: "); |
392 | @@ -310,12 +347,11 @@ |
393 | } |
394 | |
395 | sub pages_html_tidy_ok { |
396 | - my $mech = shift or die 'pages_html_tidy_ok() missing param: $mech'; |
397 | - my @pages = @_ or die 'pages_html_tidy_ok() missing param: @pages'; |
398 | + my @pages = @_ or die 'pages_html_tidy_ok() missing param: @pages'; |
399 | |
400 | foreach my $page (@pages) { |
401 | SKIP: { |
402 | - $mech->get( $$page{url} ); |
403 | + my $mech = $$page{mech}; |
404 | skip $$page{skip_reason}, 1 |
405 | if $$page{tests_to_skip} =~ 'tidy'; |
406 | my $short_page = shorten_pagename( $$page{url} ); |
407 | |
408 | === modified file 'lib-mvhub/t/lib/TestHelper.pm' |
409 | --- lib-mvhub/t/lib/TestHelper.pm 2010-10-16 00:29:43 +0000 |
410 | +++ lib-mvhub/t/lib/TestHelper.pm 2010-10-29 19:42:40 +0000 |
411 | @@ -189,6 +189,37 @@ |
412 | } |
413 | } |
414 | |
415 | +sub pages_add_ok { |
416 | + my @pages = @_ or die 'pages_add_ok() missing param: @pages'; |
417 | + my $mech; |
418 | + |
419 | + foreach my $page (@pages) { |
420 | + SKIP: { |
421 | + skip "$page->{url} $$page{skip_reason}", 3 |
422 | + if $$page{tests_to_skip} =~ 'get'; |
423 | + |
424 | + if ( not defined $$page{mech} ) { |
425 | + $$page{mech} = Test::WWW::Mechanize->new(); |
426 | + $$page{mech}->default_header( |
427 | + Authorization => TestHelper::create_temp_auth() ); |
428 | + } |
429 | + |
430 | + $mech = $$page{mech}; |
431 | + $mech->get_ok( $$page{url}, "got ok: $$page{url}" ); |
432 | + $mech->content_lacks( |
433 | + 'an error in processing your request', |
434 | + "no error in: |
435 | + " . $page->{url} |
436 | + ); |
437 | + $mech->content_contains( |
438 | + $$page{expected_content}, |
439 | + " $$page{expected_content} |
440 | + found in: $page->{url}" |
441 | + ); |
442 | + } |
443 | + } |
444 | +} |
445 | + |
446 | sub run_submit_forms_ok { |
447 | my %args = @_; |
448 | my $prefix = $args{prefix} or croak "missing param: \$prefix"; |
curious as to purpose of line #49 in diff
48 + 'mech'=>'', =>'',
49 + 'http_response'