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_hgpoller.py
346 lines (288 loc) · 12.6 KB
/
test_hgpoller.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
from twisted.internet import defer, reactor
from twisted.trial import unittest
from buildbot.util import json
if not hasattr(json.decoder, 'JSONDecodeError'):
JSONDecodeError = ValueError
else:
JSONDecodeError = json.JSONDecodeError
from buildbotcustom.changes.hgpoller import BasePoller, BaseHgPoller, HgPoller, \
HgLocalePoller, HgAllLocalesPoller, _parse_changes
from buildbotcustom.test.utils import startHTTPServer
class UrlCreation(unittest.TestCase):
def testSimpleUrl(self):
correctUrl = 'http://hg.mozilla.org/mozilla-central/json-pushes?full=1'
poller = BaseHgPoller(hgURL='http://hg.mozilla.org', branch='mozilla-central')
url = poller._make_url()
self.failUnlessEqual(url, correctUrl)
def testUrlWithLastChangeset(self):
correctUrl = 'http://hg.mozilla.org/mozilla-central/json-pushes?full=1&fromchange=123456'
poller = BaseHgPoller(hgURL='http://hg.mozilla.org', branch='mozilla-central')
poller.lastChangeset = '123456'
url = poller._make_url()
self.failUnlessEqual(url, correctUrl)
def testTipsOnlyUrl(self):
correctUrl = 'http://hg.mozilla.org/mozilla-central/json-pushes?full=1&tipsonly=1'
poller = BaseHgPoller(hgURL='http://hg.mozilla.org', branch='mozilla-central',
tipsOnly=True)
url = poller._make_url()
self.failUnlessEqual(url, correctUrl)
def testTipsOnlyWithLastChangeset(self):
# there's two possible correct URLs in this case
correctUrls = [
'http://hg.mozilla.org/releases/mozilla-1.9.1/json-pushes?full=1&fromchange=123456&tipsonly=1',
'http://hg.mozilla.org/releases/mozilla-1.9.1/json-pushes?full=1&tipsonly=1&fromchange=123456'
]
poller = BaseHgPoller(hgURL='http://hg.mozilla.org',
branch='releases/mozilla-1.9.1', tipsOnly=True)
poller.lastChangeset = '123456'
url = poller._make_url()
self.failUnlessIn(url, correctUrls)
def testOverrideUrl(self):
correctUrl = 'http://hg.mozilla.org/other_repo/json-pushes?full=1&fromchange=123456'
poller = BaseHgPoller(hgURL='http://hg.mozilla.org', branch='mozilla-central',
pushlogUrlOverride='http://hg.mozilla.org/other_repo/json-pushes?full=1')
poller.lastChangeset = '123456'
url = poller._make_url()
self.failUnlessEqual(url, correctUrl)
def testUrlWithUnicodeLastChangeset(self):
correctUrl = 'http://hg.mozilla.org/mozilla-central/json-pushes?full=1&fromchange=123456'
poller = BaseHgPoller(hgURL='http://hg.mozilla.org', branch='mozilla-central')
poller.lastChangeset = u'123456'
url = poller._make_url()
self.failUnlessEqual(url, correctUrl)
self.failUnless(isinstance(url, str))
fakeLocalesFile = """/l10n-central/af/
/l10n-central/be/
/l10n-central/de/
/l10n-central/hi/
/l10n-central/kk/
/l10n-central/zh-TW/"""
class FakeHgAllLocalesPoller(HgAllLocalesPoller):
def __init__(self):
HgAllLocalesPoller.__init__(self, hgURL='fake', repositoryIndex='fake', branch='fake')
def pollNextLocale(self):
pass
class RepositoryIndexParsing(unittest.TestCase):
def testRepositoryIndexParsing(self):
correctLocales = [('af', 'l10n-central'), ('be', 'l10n-central'),
('de', 'l10n-central'), ('hi', 'l10n-central'),
('kk', 'l10n-central'), ('zh-TW', 'l10n-central')]
poller = FakeHgAllLocalesPoller()
poller.processData(fakeLocalesFile)
self.failUnlessEqual(poller.pendingLocales, correctLocales)
class TestPolling(unittest.TestCase):
def setUp(self):
self.server, self.portnum = startHTTPServer('testcontents')
def tearDown(self):
self.server.server_close()
self.portnum = None
self.server = None
def success(self, res):
self.failUnless(self.fp.success)
def failure(self, res):
print res
self.fail()
def doPollingTest(self, poller, **kwargs):
class FakePoller(poller):
def __init__(self):
poller.__init__(self, **kwargs)
self.success = False
def stopLoad(self, res):
self.success = True
def processData(self, res): pass
def dataFinished(self, res): pass
def dataFailed(self, res): pass
def pollDone(self, res): pass
self.fp = FakePoller()
d = self.fp.poll()
d.addCallbacks(self.success, self.failure)
return d
def testHgPoller(self):
url = 'http://localhost:%s' % str(self.portnum)
return self.doPollingTest(HgPoller, hgURL=url, branch='whatever')
def testHgLocalePoller(self):
url = 'http://localhost:%s' % str(self.portnum)
return self.doPollingTest(HgLocalePoller, locale='fake', parent='fake',
hgURL=url, branch='whatever')
def testHgAllLocalesPoller(self):
url = 'http://localhost:%s' % str(self.portnum)
return self.doPollingTest(HgAllLocalesPoller, hgURL=url,
repositoryIndex='foobar')
validPushlog = """
{
"15226": {
"date": 1282358416,
"changesets": [
{
"node": "4c23e51a484f077ea27af3ea4a4ee13da5aeb5e6",
"files": [
"embedding/android/GeckoInputConnection.java",
"embedding/android/GeckoSurfaceView.java",
"widget/src/android/nsWindow.cpp",
"widget/src/android/nsWindow.h"
],
"tags": [],
"author": "Jim Chen <jchen@mozilla.com>",
"branch": "GECKO20b5pre_20100820_RELBRANCH",
"desc": "Bug 588456 - Properly commit Android IME composition on blur; r=mwu a=blocking-fennec"
}
],
"user": "dougt@mozilla.com"
},
"15227": {
"date": 1282362551,
"changesets": [
{
"node": "ee6fb954cbc3de0f76e84cad6bdff452116e1b03",
"files": [
"browser/base/content/browser.js",
"browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml",
"browser/locales/en-US/chrome/overrides/netError.dtd",
"build/automation.py.in",
"docshell/resources/content/netError.xhtml",
"dom/locales/en-US/chrome/netErrorApp.dtd",
"extensions/cookie/nsPermissionManager.cpp"
],
"tags": [],
"author": "Bobby Holley <bobbyholley@gmail.com>",
"branch": "default",
"desc": "Backout of changesets c866e73f3209 and baff7b7b32bc because of sicking's push-and-run bustage. a=backout"
},
{
"node": "33be08836cb164f9e546231fc59e9e4cf98ed991",
"files": [
"modules/libpref/src/init/all.js"
],
"tags": [],
"author": "Bobby Holley <bobbyholley@gmail.com>",
"branch": "default",
"desc": "Bug 563088 - Re-enable image discarding.r=joe,a=blocker"
}
],
"user": "bobbyholley@stanford.edu"
}
}
"""
malformedPushlog = """
{
"15226": {
"date": 1282358416,
"changesets": [
{
"node": "4c23e51a484f077ea27af3ea4a4ee13da5aeb5e6",
"files": [
"embedding/android/GeckoInputConnection.java",
"embedding/android/GeckoSurfaceView.java",
"widget/src/android/nsWindow.cpp",
"widget/src/android/nsWindow.h"
],
"tags": [],
"author": "Jim Chen <jchen@mozilla.com>",
"branch": "GECKO20b5pre_20100820_RELBRANCH",
"desc": "Bug 588456 - Properly commit Android IME composition on blur; r=mwu a=blocking-fennec"
}
],
"user": "dougt@mozilla.com"
"""
class PushlogParsing(unittest.TestCase):
def testValidPushlog(self):
changes = _parse_changes(validPushlog)
self.failUnlessEqual(len(changes), 3)
self.failUnlessEqual(changes[0]['changeset'], '4c23e51a484f077ea27af3ea4a4ee13da5aeb5e6')
self.failUnlessEqual(changes[0]['updated'], 1282358416)
self.failUnlessEqual(len(changes[0]['files']), 4)
self.failUnlessEqual(changes[0]['branch'], 'GECKO20b5pre_20100820_RELBRANCH')
self.failUnlessEqual(changes[0]['author'], 'dougt@mozilla.com')
self.failUnlessEqual(changes[1]['changeset'], 'ee6fb954cbc3de0f76e84cad6bdff452116e1b03')
self.failUnlessEqual(changes[1]['updated'], 1282362551)
self.failUnlessEqual(len(changes[1]['files']), 7)
self.failUnlessEqual(changes[1]['branch'], 'default')
self.failUnlessEqual(changes[1]['author'], 'bobbyholley@stanford.edu')
self.failUnlessEqual(changes[2]['changeset'], '33be08836cb164f9e546231fc59e9e4cf98ed991')
self.failUnlessEqual(changes[2]['updated'], 1282362551)
self.failUnlessEqual(len(changes[2]['files']), 1)
self.failUnlessEqual(changes[2]['branch'], 'default')
self.failUnlessEqual(changes[2]['author'], 'bobbyholley@stanford.edu')
def testMalformedPushlog(self):
self.failUnlessRaises(JSONDecodeError, _parse_changes, malformedPushlog)
def testEmptyPushlog(self):
self.failUnlessRaises(JSONDecodeError, _parse_changes, "")
class RepoBranchHandling(unittest.TestCase):
def setUp(self):
self.changes = []
def doTest(self, repo_branch):
changes = self.changes
class TestPoller(BaseHgPoller):
def __init__(self):
BaseHgPoller.__init__(self, 'http://localhost', 'whatever',
repo_branch=repo_branch)
self.emptyRepo = True
class parent:
def addChange(self, change):
changes.append(change)
p = TestPoller()
p.parent = parent()
p.processData(validPushlog)
def testNoRepoBranch(self):
self.doTest(None)
self.assertEquals(len(self.changes), 3)
def testDefaultRepoBranch(self):
self.doTest('default')
self.assertEquals(len(self.changes), 2)
def testRelbranch(self):
self.doTest('GECKO20b5pre_20100820_RELBRANCH')
self.assertEquals(len(self.changes), 1)
self.assertEquals(self.changes[0].revision, '4c23e51a484f077ea27af3ea4a4ee13da5aeb5e6')
class MaxChangesHandling(unittest.TestCase):
def setUp(self):
self.changes = []
def doTest(self, repo_branch, maxChanges):
changes = self.changes
class TestPoller(BaseHgPoller):
def __init__(self):
BaseHgPoller.__init__(self, 'http://localhost', 'whatever',
repo_branch=repo_branch, maxChanges=maxChanges)
self.emptyRepo = True
class parent:
def addChange(self, change):
changes.append(change)
p = TestPoller()
p.parent = parent()
p.processData(validPushlog)
def testNoRepoBigMax(self):
# Test that we get all of the changes when maxChanges is large enough
self.doTest(None, 10)
self.assertEquals(len(self.changes), 3)
# Check that we got the right changes
self.assertEquals(self.changes[0].revision, '4c23e51a484f077ea27af3ea4a4ee13da5aeb5e6')
self.assertEquals(self.changes[1].revision, 'ee6fb954cbc3de0f76e84cad6bdff452116e1b03')
self.assertEquals(self.changes[2].revision, '33be08836cb164f9e546231fc59e9e4cf98ed991')
def testNoRepoUnlimited(self):
# Test that we get all of the changes when maxChanges is large enough
self.doTest(None, None)
self.assertEquals(len(self.changes), 3)
# Check that we got the right changes
self.assertEquals(self.changes[0].revision, '4c23e51a484f077ea27af3ea4a4ee13da5aeb5e6')
self.assertEquals(self.changes[1].revision, 'ee6fb954cbc3de0f76e84cad6bdff452116e1b03')
self.assertEquals(self.changes[2].revision, '33be08836cb164f9e546231fc59e9e4cf98ed991')
def testNoRepoSmallMax(self):
# Test that we get only 2 changes if maxChanges is set to 2
self.doTest(None, 2)
self.assertEquals(len(self.changes), 2)
# Check that we got the right changes
self.assertEquals(self.changes[0].revision, 'ee6fb954cbc3de0f76e84cad6bdff452116e1b03')
self.assertEquals(self.changes[1].revision, '33be08836cb164f9e546231fc59e9e4cf98ed991')
def testDefaultRepoBigMax(self):
self.doTest('default', 10)
self.assertEquals(len(self.changes), 2)
# Check that we got the right changes
self.assertEquals(self.changes[0].revision, 'ee6fb954cbc3de0f76e84cad6bdff452116e1b03')
self.assertEquals(self.changes[1].revision, '33be08836cb164f9e546231fc59e9e4cf98ed991')
def testDefaultRepoSmallMax(self):
self.doTest('default', 1)
self.assertEquals(len(self.changes), 1)
# Check that we got the right changes
self.assertEquals(self.changes[0].revision, '33be08836cb164f9e546231fc59e9e4cf98ed991')
def testRelbranchSmallMax(self):
self.doTest('GECKO20b5pre_20100820_RELBRANCH', 0)
self.assertEquals(len(self.changes), 0)