This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_test_order.py
365 lines (295 loc) · 13.8 KB
/
test_test_order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import os, shutil
from twisted.trial import unittest
from twisted.python import log
from twisted.internet import defer
from buildbot.schedulers.basic import Scheduler
from buildbot.db import dbspec, connector
from buildbot.db.schema.manager import DBSchemaManager
from buildbot.changes.changes import Change
from buildbot.process.builder import Builder
from buildbot.changes.manager import ChangeManager
from buildbot.process.factory import BuildFactory
from buildbot.steps.dummy import Dummy
from buildbot.sourcestamp import SourceStamp
from buildbot.process.properties import Properties
from buildbotcustom.process.factory import RequestSortingBuildFactory
import mock
class TestTestOrder(unittest.TestCase):
"""Tests that tests are run according to their corresponding build's start
time"""
basedir = "test_test_order"
def setUp(self):
if os.path.exists(self.basedir):
shutil.rmtree(self.basedir)
os.makedirs(self.basedir)
spec = dbspec.DBSpec.from_url("sqlite:///state.sqlite", self.basedir)
manager = DBSchemaManager(spec, self.basedir)
manager.upgrade()
self.dbc = connector.DBConnector(spec)
self.dbc.start()
parent = mock.Mock()
parent.db = self.dbc
change_manager = ChangeManager()
change_manager.parent = parent
parent.change_svc = change_manager
self.s = Scheduler(name="s", builderNames=["b1"])
self.s.parent = parent
return self.dbc.addSchedulers([self.s])
def makeBuilder(self, klass):
dummy_factory = klass([Dummy()])
builder = {
'name': 'b1',
'slavenames': ['s1'],
'builddir': 'b1',
'slavebuilddir': 'b1',
'factory': dummy_factory,
}
builder_status = mock.Mock()
builder = Builder(builder, builder_status)
builder.running = True
builder.db = self.dbc
builder.master_name = 'test_master'
builder.master_incarnation = '12345'
builder.botmaster = mock.Mock()
builder.botmaster.shouldMergeRequests.return_value = True
return builder
def tearDown(self):
self.dbc.stop()
shutil.rmtree(self.basedir)
def test_singleRequest(self):
# Easy peasy
c1 = Change(who='me!', branch='b1', revision='1', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000001'})
self.dbc.addChangeToDatabase(c1)
builder = self.makeBuilder(BuildFactory)
# Run the scheduler
d = self.s.run()
# Check that we have a build request
def checkRequests(ign):
req = self.dbc.runQueryNow("select count(*) from buildrequests")
self.assertEquals(req[0][0], 1)
d.addCallback(checkRequests)
# Claim the request
def claimRequest(ign):
d = self.dbc.runInteraction(builder._claim_buildreqs, ["slave!"])
return d
d.addCallback(claimRequest)
# Start the build!
def startBuild(assignments):
self.assertEquals(len(assignments.keys()), 1)
requests = assignments.values()[0]
self.assertEquals(len(requests), 1)
build = builder.buildFactory.newBuild(requests)
self.assertEquals(build.source.revision, '1')
changes = build.source.changes
self.assertEquals(changes[0].revision, '1')
return
d.addCallback(startBuild)
return d
def test_threeRequests(self):
# Three changes, r1, r2, r3
# They start in order, and finish in reverse order
# We want the to be testing r3 in the end
c1 = Change(who='me!', branch='b1', revision='r3', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000003'}, when=4)
c2 = Change(who='me!', branch='b1', revision='r2', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000002'}, when=5)
c3 = Change(who='me!', branch='b1', revision='r1', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000001'}, when=6)
self.dbc.addChangeToDatabase(c1)
self.dbc.addChangeToDatabase(c2)
self.dbc.addChangeToDatabase(c3)
# Run the scheduler
d = self.s.run()
builder = self.makeBuilder(RequestSortingBuildFactory)
# Check that we have three build requests
def checkRequests(ign):
req = self.dbc.runQueryNow("select count(*) from buildrequests")
self.assertEquals(req[0][0], 3)
d.addCallback(checkRequests)
# Claim the request
def claimRequest(ign):
d = self.dbc.runInteraction(builder._claim_buildreqs, ["slave!"])
return d
d.addCallback(claimRequest)
# Start the build!
def startBuild(assignments):
self.assertEquals(len(assignments.keys()), 1)
requests = assignments.values()[0]
self.assertEquals(len(requests), 3)
build = builder.buildFactory.newBuild(requests)
self.assertEquals(build.source.revision, 'r3')
changes = build.source.changes
# The last revision should be r3, since it started latest
self.assertEquals(changes[0].revision, 'r1')
self.assertEquals(changes[1].revision, 'r2')
self.assertEquals(changes[2].revision, 'r3')
return
d.addCallback(startBuild)
return d
def test_threeRequestsUnsorted(self):
# Three changes, r1, r2, r3
# They start in order, and finish in reverse order
# We want the to be testing r3 in the end
c1 = Change(who='me!', branch='b1', revision='r3', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000003'}, when=4)
c2 = Change(who='me!', branch='b1', revision='r2', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000002'}, when=5)
c3 = Change(who='me!', branch='b1', revision='r1', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000001'}, when=6)
self.dbc.addChangeToDatabase(c1)
self.dbc.addChangeToDatabase(c2)
self.dbc.addChangeToDatabase(c3)
# Run the scheduler
d = self.s.run()
builder = self.makeBuilder(BuildFactory)
# Check that we have three build requests
def checkRequests(ign):
req = self.dbc.runQueryNow("select count(*) from buildrequests")
self.assertEquals(req[0][0], 3)
d.addCallback(checkRequests)
# Claim the request
def claimRequest(ign):
d = self.dbc.runInteraction(builder._claim_buildreqs, ["slave!"])
return d
d.addCallback(claimRequest)
# Start the build!
def startBuild(assignments):
self.assertEquals(len(assignments.keys()), 1)
requests = assignments.values()[0]
self.assertEquals(len(requests), 3)
build = builder.buildFactory.newBuild(requests)
self.assertEquals(build.source.revision, 'r1')
changes = build.source.changes
# The last revision should be r1, since it was submitted latest
self.assertEquals(changes[0].revision, 'r3')
self.assertEquals(changes[1].revision, 'r2')
self.assertEquals(changes[2].revision, 'r1')
return
d.addCallback(startBuild)
return d
def test_threeRequestsManual(self):
# Three changes, r1, r2, r3
# r2, and r3 have buildids
# r1 is manually triggered, and is submitted later
# we want to be testing r1 in the end
c1 = Change(who='me!', branch='b1', revision='r3', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000003'}, when=4)
c2 = Change(who='me!', branch='b1', revision='r2', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000002'}, when=5)
c3 = Change(who='me!', branch='b1', revision='r1', files=['http://path/to/build'],
comments='really important', when=6)
self.dbc.addChangeToDatabase(c1)
self.dbc.addChangeToDatabase(c2)
self.dbc.addChangeToDatabase(c3)
# Run the scheduler
d = self.s.run()
builder = self.makeBuilder(RequestSortingBuildFactory)
# Check that we have three build requests
def checkRequests(ign):
req = self.dbc.runQueryNow("select count(*) from buildrequests")
self.assertEquals(req[0][0], 3)
d.addCallback(checkRequests)
# Claim the request
def claimRequest(ign):
d = self.dbc.runInteraction(builder._claim_buildreqs, ["slave!"])
return d
d.addCallback(claimRequest)
# Start the build!
def startBuild(assignments):
self.assertEquals(len(assignments.keys()), 1)
requests = assignments.values()[0]
self.assertEquals(len(requests), 3)
build = builder.buildFactory.newBuild(requests)
self.assertEquals(build.source.revision, 'r1')
changes = build.source.changes
# The last revision should be r1, since it was manually triggered later
self.assertEquals(changes[0].revision, 'r2')
self.assertEquals(changes[1].revision, 'r3')
self.assertEquals(changes[2].revision, 'r1')
return
d.addCallback(startBuild)
return d
def test_Rebuilds(self):
# Two changes, r2, r3
# They start in order, and finish in reverse order
# We also have a pending request to re-build r1 that happens after r2, r3 have started
# We want to end up re-building r1
c1 = Change(who='me!', branch='b1', revision='r3', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000003'}, when=4)
c2 = Change(who='me!', branch='b1', revision='r2', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000002'}, when=5)
self.dbc.addChangeToDatabase(c1)
self.dbc.addChangeToDatabase(c2)
# Run the scheduler
d = self.s.run()
# Rebuild r1
def addRebuild(t):
c3 = Change(who='me!', branch='b1', revision='r1', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000001'}, when=6)
self.dbc.addChangeToDatabase(c3)
ss = SourceStamp(branch='b1', changes=[c3], revision='r1')
ss1 = ss.getAbsoluteSourceStamp('r1')
ssid = self.dbc.get_sourcestampid(ss, t)
bsid = self.dbc.create_buildset(ssid, "rebuild", Properties(), ["b1"], t)
d.addCallback(lambda ign: self.dbc.runInteractionNow(addRebuild))
builder = self.makeBuilder(RequestSortingBuildFactory)
# Check that we have three build requests
def checkRequests(ign):
req = self.dbc.runQueryNow("select count(*) from buildrequests")
self.assertEquals(req[0][0], 3)
d.addCallback(checkRequests)
# Claim the request
def claimRequest(ign):
d = self.dbc.runInteraction(builder._claim_buildreqs, ["slave!"])
return d
d.addCallback(claimRequest)
# Start the build!
def startBuild(assignments):
self.assertEquals(len(assignments.keys()), 1)
requests = assignments.values()[0]
self.assertEquals(len(requests), 3)
build = builder.buildFactory.newBuild(requests)
self.assertEquals(build.source.revision, 'r1')
changes = build.source.changes
# The last revision should be r1, since it was manually triggered later
self.assertEquals(changes[0].revision, 'r2')
self.assertEquals(changes[1].revision, 'r3')
self.assertEquals(changes[2].revision, 'r1')
return
d.addCallback(startBuild)
return d
def test_brokenRequest(self):
c1 = Change(who='me!', branch='b1', revision='1', files=['http://path/to/build'],
comments='really important', properties={'buildid': '20110214000001'})
self.dbc.addChangeToDatabase(c1)
builder = self.makeBuilder(RequestSortingBuildFactory)
# Run the scheduler
d = self.s.run()
# Check that we have a build request
def checkRequests(ign):
req = self.dbc.runQueryNow("select count(*) from buildrequests")
self.assertEquals(req[0][0], 1)
d.addCallback(checkRequests)
# Claim the request
def claimRequest(ign):
d = self.dbc.runInteraction(builder._claim_buildreqs, ["slave!"])
return d
d.addCallback(claimRequest)
# Start the build!
def startBuild(assignments):
self.assertEquals(len(assignments.keys()), 1)
requests = assignments.values()[0]
# Hack the request to break the sorting
requests[0].submittedAt = "asdf"
requests[0].reason = "rebuild"
self.assertEquals(len(requests), 1)
build = builder.buildFactory.newBuild(requests)
# This should have generated an error
self.failUnless(len(self.flushLoggedErrors()) == 1)
self.assertEquals(build.source.revision, '1')
changes = build.source.changes
self.assertEquals(changes[0].revision, '1')
return
d.addCallback(startBuild)
return d