488
500
self._test_packagesets(
489
501
html, packageset_text, 'parent-packagesets', 'Parent packagesets')
503
def test_queries(self):
504
# With no DistroSeriesDifferences the query count should be low and
505
# fairly static. However, with some DistroSeriesDifferences the query
506
# count will be higher, but it should remain the same no matter how
507
# many differences there are.
508
login_person(self.simple_user)
509
derived_series = self.factory.makeDistroSeries(
510
parent_series=self.factory.makeDistroSeries())
512
def add_differences(num):
513
for index in xrange(num):
514
version = self.factory.getUniqueInteger()
516
'base': u'1.%d' % version,
517
'derived': u'1.%dderived1' % version,
518
'parent': u'1.%d-1' % version,
520
dsd = self.factory.makeDistroSeriesDifference(
521
derived_series=derived_series,
524
# Push a base_version in... not sure how better to do it.
525
removeSecurityProxy(dsd).base_version = versions["base"]
527
# Add a couple of comments.
528
self.factory.makeDistroSeriesDifferenceComment(dsd)
529
self.factory.makeDistroSeriesDifferenceComment(dsd)
531
# Update the spr, some with recipes, some with signing keys.
532
# SPR.uploader references both, and the uploader is referenced
534
spr = dsd.source_pub.sourcepackagerelease
536
removeSecurityProxy(spr).source_package_recipe_build = (
537
self.factory.makeSourcePackageRecipeBuild(
538
sourcename=spr.sourcepackagename.name,
539
distroseries=derived_series))
541
removeSecurityProxy(spr).dscsigningkey = (
542
self.factory.makeGPGKey(owner=spr.creator))
544
def flush_and_render():
545
flush_database_caches()
546
# Pull in the calling user's location so that it isn't recorded in
547
# the query count; it causes the total to be fragile for no
548
# readily apparent reason.
549
self.simple_user.location
550
with StormStatementRecorder() as recorder:
551
view = create_initialized_view(
552
derived_series, '+localpackagediffs',
553
principal=self.simple_user)
555
return recorder, view.cached_differences.batch.trueSize
557
def statement_differ(rec1, rec2):
558
wrapper = TextWrapper(break_long_words=False)
560
def prepare_statements(rec):
561
for statement in rec.statements:
562
for line in wrapper.wrap(statement):
564
yield "-" * wrapper.width
566
def statement_diff():
567
diff = difflib.ndiff(
568
list(prepare_statements(rec1)),
569
list(prepare_statements(rec2)))
573
return statement_diff
575
# Render without differences and check the query count isn't silly.
576
recorder1, batch_size = flush_and_render()
577
self.assertThat(recorder1, HasQueryCount(LessThan(30)))
579
"statement-count-0-differences",
580
text_content(u"%d" % recorder1.count))
581
# Add some differences and render.
583
recorder2, batch_size = flush_and_render()
585
"statement-count-2-differences",
586
text_content(u"%d" % recorder2.count))
587
# Add more differences and render again.
589
recorder3, batch_size = flush_and_render()
591
"statement-count-4-differences",
592
text_content(u"%d" % recorder3.count))
593
# The last render should not need more queries than the previous.
595
"statement-diff", Content(
596
UTF8_TEXT, statement_differ(recorder2, recorder3)))
597
# Details about the number of statements per row.
598
statement_count_per_row = (
599
(recorder3.count - recorder1.count) / float(batch_size))
601
"statement-count-per-row-average",
602
text_content(u"%.2f" % statement_count_per_row))
603
# XXX: GavinPanella 2011-04-12 bug=760733: Reducing the query count
604
# further needs work. Ideally this test would be along the lines of
605
# recorder3.count == recorder2.count. 4 queries above the recorder2
606
# count is 2 queries per difference which is not acceptable, but is
607
# *far* better than without the changes introduced by landing this.
608
compromise_statement_count = recorder2.count + 4
610
recorder3, HasQueryCount(
611
LessThan(compromise_statement_count + 1)))
492
614
class TestDistroSeriesLocalDifferencesZopeless(TestCaseWithFactory):
493
615
"""Test the distroseries +localpackagediffs view."""