~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/browser/tests/test_builder.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-07 17:40:43 UTC
  • mfrom: (14513.3.18 builders-timeout-903827-2)
  • Revision ID: launchpad@pqm.canonical.com-20120107174043-8a8bkggm6n638o0f
[r=jcsackett][bug=903827] Make buildqueue.specific_job and
        builder.currentjob cached properties.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010-2012 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Tests for the lp.soyuz.browser.builder module."""
67
67
 
68
68
    layer = LaunchpadFunctionalLayer
69
69
 
70
 
    # XXX rvb: the 3 additional queries per build are the result of the calls
71
 
    # to:
72
 
    # - builder.currentjob
73
 
    # - buildqueue.specific_job
74
 
    # These could be converted into cachedproperty and pre-populated in
75
 
    # bulk but several tests assert that the value returned by these
76
 
    # these properties are up to date.  Since they are not really expensive
77
 
    # to compute I'll leave them as regular properties for now.
 
70
    # XXX rvb: the query issued per build is the result of the call to
 
71
    # build.buildqueue_record.  It was decided not to make it a cachedproperty
 
72
    # because the code relies on the fact that this property always returns
 
73
    # the current record.
78
74
 
79
75
    def test_builders_binary_package_build_query_count(self):
80
76
        def create_build():
82
78
            queue = build.queueBuild()
83
79
            queue.markAsBuilding(build.builder)
84
80
 
 
81
        nb_objects = 2
85
82
        recorder1, recorder2 = record_two_runs(
86
 
            builders_homepage_render, create_build, 2)
 
83
            builders_homepage_render, create_build, nb_objects)
87
84
 
88
85
        self.assertThat(
89
86
            recorder2,
90
 
            HasQueryCount(LessThan(recorder1.count + 3 * 2 + 1)))
 
87
            HasQueryCount(LessThan(recorder1.count + 1 * nb_objects + 1)))
91
88
 
92
89
    def test_builders_recipe_build_query_count(self):
93
90
        def create_build():
95
92
            queue = build.queueBuild()
96
93
            queue.markAsBuilding(build.builder)
97
94
 
 
95
        nb_objects = 2
98
96
        recorder1, recorder2 = record_two_runs(
99
 
            builders_homepage_render, create_build, 2)
 
97
            builders_homepage_render, create_build, nb_objects)
100
98
 
101
99
        self.assertThat(
102
100
            recorder2,
103
 
            HasQueryCount(LessThan(recorder1.count + 3 * 2 + 1)))
 
101
            HasQueryCount(LessThan(recorder1.count + 1 * nb_objects + 1)))
104
102
 
105
103
    def test_builders_translation_template_build_query_count(self):
106
104
        def create_build():
114
112
            queue = queueset.get(job_id)
115
113
            queue.markAsBuilding(self.factory.makeBuilder())
116
114
 
 
115
        nb_objects = 2
117
116
        recorder1, recorder2 = record_two_runs(
118
 
            builders_homepage_render, create_build, 2)
 
117
            builders_homepage_render, create_build, nb_objects)
119
118
 
120
119
        self.assertThat(
121
120
            recorder2,
122
 
            HasQueryCount(LessThan(recorder1.count + 3 * 2 + 1)))
 
121
            HasQueryCount(LessThan(recorder1.count + 1 * nb_objects + 1)))