63
70
layer = LaunchpadFunctionalLayer
65
def createRecipeBuildWithBuilder(self, builder=None):
66
build = self.factory.makeSourcePackageRecipeBuild()
75
super(TestBuilderHistoryView, self).setUp()
76
self.builder = self.factory.makeBuilder()
78
def createTranslationTemplateBuildWithBuilder(self):
79
build_farm_job_source = getUtility(IBuildFarmJobSource)
80
build_farm_job = build_farm_job_source.new(
81
BuildFarmJobType.TRANSLATIONTEMPLATESBUILD)
82
source = getUtility(ITranslationTemplatesBuildSource)
83
branch = self.factory.makeBranch()
84
build = source.create(build_farm_job, branch)
85
removeSecurityProxy(build).builder = self.builder
88
def createRecipeBuildWithBuilder(self):
89
branch1 = self.factory.makeAnyBranch()
90
branch2 = self.factory.makeAnyBranch()
91
build = self.factory.makeSourcePackageRecipeBuild(
92
recipe=self.factory.makeSourcePackageRecipe(
93
branches=[branch1, branch2]))
67
94
Store.of(build).flush()
69
builder = self.factory.makeBuilder()
70
removeSecurityProxy(build).builder = builder
73
def test_build_history_queries_count(self):
74
# The number of queries issued by setupBuildList is not dependent
75
# on the number of builds.
76
builder = self.factory.makeBuilder()
77
self.createRecipeBuildWithBuilder(builder)
78
self.createRecipeBuildWithBuilder(builder)
79
# Record how many queries are issued when setupBuildList is
80
# called with 2 builds.
95
removeSecurityProxy(build).builder = self.builder
98
def createBinaryPackageBuild(self):
99
build = self.factory.makeBinaryPackageBuild()
100
removeSecurityProxy(build).builder = self.builder
103
def _record_queries_count(self, tested_method, item_creator):
104
# A simple helper that returns the two storm statement recorders
105
# obtained when running tested_method with {nb_objects} items creater
106
# (using item_creator) and then with {nb_objects}*2 items created.
107
for i in range(self.nb_objects):
109
# Record how many queries are issued when tested_method is
110
# called with {nb_objects} items created.
111
flush_database_caches()
81
112
with StormStatementRecorder() as recorder1:
82
view = create_initialized_view(builder, '+history')
84
self.assertEqual(2, len(view.complete_builds))
85
# Create two more builds.
86
self.createRecipeBuildWithBuilder(builder)
87
self.createRecipeBuildWithBuilder(builder)
114
# Create {nb_objects} more items.
115
for i in range(self.nb_objects):
88
117
# Record again the number of queries issued.
118
flush_database_caches()
89
119
with StormStatementRecorder() as recorder2:
90
view = create_initialized_view(builder, '+history')
92
self.assertEqual(4, len(view.complete_builds))
121
return recorder1, recorder2
123
def test_build_history_queries_count_view_recipe_builds(self):
124
# The builder's history view creation (i.e. the call to
125
# view.setupBuildList) issues a constant number of queries
126
# when recipe builds are displayed.
127
def builder_history_render():
128
create_initialized_view(self.builder, '+history').render()
129
recorder1, recorder2 = self._record_queries_count(
130
builder_history_render,
131
self.createRecipeBuildWithBuilder)
133
# XXX: rvb 2011-11-14 bug=890326: The only query remaining is the
134
# one that results from a call to
135
# sourcepackagerecipebuild.buildqueue_record for each recipe build.
138
HasQueryCount(Equals(recorder1.count + 1 * self.nb_objects)))
140
def test_build_history_queries_count_binary_package_builds(self):
141
# Rendering to builder's history issues a constant number of queries
142
# when binary builds are displayed.
143
def builder_history_render():
144
create_initialized_view(self.builder, '+history').render()
145
recorder1, recorder2 = self._record_queries_count(
146
builder_history_render,
147
self.createBinaryPackageBuild)
149
self.assertThat(recorder2, HasQueryCount(Equals(recorder1.count)))
151
def test_build_history_queries_count_translation_template_builds(self):
152
# Rendering to builder's history issues a constant number of queries
153
# when translation template builds are displayed.
154
def builder_history_render():
155
create_initialized_view(self.builder, '+history').render()
156
recorder1, recorder2 = self._record_queries_count(
157
builder_history_render,
158
self.createTranslationTemplateBuildWithBuilder)
94
160
self.assertThat(recorder2, HasQueryCount(Equals(recorder1.count)))