1 | # -*- coding: utf-8 -*- |
---|
2 | # |
---|
3 | # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de> |
---|
4 | # Copyright (C) 2007-2010 Edgewall Software |
---|
5 | # All rights reserved. |
---|
6 | # |
---|
7 | # This software is licensed as described in the file COPYING, which |
---|
8 | # you should have received as part of this distribution. The terms |
---|
9 | # are also available at http://bitten.edgewall.org/wiki/License. |
---|
10 | |
---|
11 | import os |
---|
12 | import shutil |
---|
13 | import tempfile |
---|
14 | import threading |
---|
15 | import time |
---|
16 | import unittest |
---|
17 | |
---|
18 | from trac.db import DatabaseManager |
---|
19 | from trac.test import EnvironmentStub, Mock |
---|
20 | from trac.util.datefmt import to_datetime, utc |
---|
21 | from bitten.model import BuildConfig, TargetPlatform, Build, schema |
---|
22 | from bitten.queue import BuildQueue, collect_changes |
---|
23 | |
---|
24 | |
---|
25 | class CollectChangesTestCase(unittest.TestCase): |
---|
26 | """ |
---|
27 | Unit tests for the `bitten.queue.collect_changes` function. |
---|
28 | """ |
---|
29 | |
---|
30 | def setUp(self): |
---|
31 | self.env = EnvironmentStub(enable=['trac.*', 'bitten.*']) |
---|
32 | self.env.path = tempfile.mkdtemp() |
---|
33 | |
---|
34 | db = self.env.get_db_cnx() |
---|
35 | cursor = db.cursor() |
---|
36 | connector, _ = DatabaseManager(self.env)._get_connector() |
---|
37 | for table in schema: |
---|
38 | for stmt in connector.to_sql(table): |
---|
39 | cursor.execute(stmt) |
---|
40 | |
---|
41 | self.config = BuildConfig(self.env, name='test', path='somepath') |
---|
42 | self.config.insert(db=db) |
---|
43 | self.platform = TargetPlatform(self.env, config='test', name='Foo') |
---|
44 | self.platform.insert(db=db) |
---|
45 | db.commit() |
---|
46 | |
---|
47 | # Hook up a dummy repository |
---|
48 | self.repos = Mock() |
---|
49 | self.env.get_repository = lambda authname=None: self.repos # 0.11 |
---|
50 | try: # 0.12+ |
---|
51 | from trac.core import Component, implements |
---|
52 | from trac.versioncontrol.api import IRepositoryConnector, \ |
---|
53 | IRepositoryProvider |
---|
54 | class DummyRepos(Component): |
---|
55 | implements(IRepositoryConnector, IRepositoryProvider) |
---|
56 | def get_supported_types(self): |
---|
57 | yield ('dummy', 9) |
---|
58 | def get_repository(this, repos_type, repos_dir, params): |
---|
59 | return self.repos # Note: 'this' vs 'self' usage |
---|
60 | def get_repositories(self): |
---|
61 | yield ('', {'dir': 'dummy_dir', 'type': 'dummy'}) |
---|
62 | self.dummy = DummyRepos |
---|
63 | except ImportError: |
---|
64 | self.dummy = None # not supported, will use get_repository() |
---|
65 | |
---|
66 | def tearDown(self): |
---|
67 | if self.dummy: # remove from components list + interfaces dict |
---|
68 | self.env.__metaclass__._components.remove(self.dummy) |
---|
69 | for key in self.env.__metaclass__._registry.keys(): |
---|
70 | if self.dummy in self.env.__metaclass__._registry[key]: |
---|
71 | self.env.__metaclass__._registry[key].remove(self.dummy) |
---|
72 | shutil.rmtree(self.env.path) |
---|
73 | |
---|
74 | def test_stop_on_copy(self): |
---|
75 | |
---|
76 | self.repos.get_node=lambda path, rev=None: Mock( |
---|
77 | get_history=lambda: [('otherpath', 123, 'copy')]) |
---|
78 | self.repos.normalize_path=lambda path: path |
---|
79 | |
---|
80 | retval = list(collect_changes(self.config)) |
---|
81 | self.assertEqual(0, len(retval)) |
---|
82 | |
---|
83 | def test_stop_on_minrev(self): |
---|
84 | self.repos.get_node=lambda path, rev=None: Mock( |
---|
85 | get_entries=lambda: [Mock(), Mock()], |
---|
86 | get_history=lambda: [('somepath', 123, 'edit'), |
---|
87 | ('somepath', 121, 'edit'), |
---|
88 | ('somepath', 120, 'edit')]) |
---|
89 | self.repos.normalize_path=lambda path: path |
---|
90 | self.repos.rev_older_than=lambda rev1, rev2: rev1 < rev2 |
---|
91 | |
---|
92 | self.config.min_rev = 123 |
---|
93 | self.config.update() |
---|
94 | |
---|
95 | retval = list(collect_changes(self.config)) |
---|
96 | self.assertEqual(1, len(retval)) |
---|
97 | self.assertEqual(123, retval[0][1]) |
---|
98 | |
---|
99 | def test_skip_until_maxrev(self): |
---|
100 | self.repos.get_node=lambda path, rev=None: Mock( |
---|
101 | get_entries=lambda: [Mock(), Mock()], |
---|
102 | get_history=lambda: [('somepath', 123, 'edit'), |
---|
103 | ('somepath', 121, 'edit'), |
---|
104 | ('somepath', 120, 'edit')]) |
---|
105 | self.repos.normalize_path=lambda path: path |
---|
106 | self.repos.rev_older_than=lambda rev1, rev2: rev1 < rev2 |
---|
107 | |
---|
108 | self.config.max_rev=121 |
---|
109 | self.config.update() |
---|
110 | |
---|
111 | retval = list(collect_changes(self.config)) |
---|
112 | self.assertEqual(2, len(retval)) |
---|
113 | self.assertEqual(121, retval[0][1]) |
---|
114 | self.assertEqual(120, retval[1][1]) |
---|
115 | |
---|
116 | def test_skip_empty_dir(self): |
---|
117 | def _mock_get_node(path, rev=None): |
---|
118 | if rev and rev == 121: |
---|
119 | return Mock( |
---|
120 | get_entries=lambda: [] |
---|
121 | ) |
---|
122 | else: |
---|
123 | return Mock( |
---|
124 | get_entries=lambda: [Mock(), Mock()], |
---|
125 | get_history=lambda: [('somepath', 123, 'edit'), |
---|
126 | ('somepath', 121, 'edit'), |
---|
127 | ('somepath', 120, 'edit')] |
---|
128 | ) |
---|
129 | |
---|
130 | self.repos.get_node=_mock_get_node |
---|
131 | self.repos.normalize_path=lambda path: path |
---|
132 | self.repos.rev_older_than=lambda rev1, rev2: rev1 < rev2 |
---|
133 | |
---|
134 | retval = list(collect_changes(self.config)) |
---|
135 | self.assertEqual(2, len(retval)) |
---|
136 | self.assertEqual(123, retval[0][1]) |
---|
137 | self.assertEqual(120, retval[1][1]) |
---|
138 | |
---|
139 | |
---|
140 | class BuildQueueTestCase(unittest.TestCase): |
---|
141 | |
---|
142 | def setUp(self): |
---|
143 | self.env = EnvironmentStub(enable=['trac.*', 'bitten.*']) |
---|
144 | self.env.path = tempfile.mkdtemp() |
---|
145 | |
---|
146 | db = self.env.get_db_cnx() |
---|
147 | cursor = db.cursor() |
---|
148 | connector, _ = DatabaseManager(self.env)._get_connector() |
---|
149 | for table in schema: |
---|
150 | for stmt in connector.to_sql(table): |
---|
151 | cursor.execute(stmt) |
---|
152 | db.commit() |
---|
153 | |
---|
154 | # Hook up a dummy repository |
---|
155 | self.repos = Mock() |
---|
156 | self.env.get_repository = lambda authname=None: self.repos # 0.11 |
---|
157 | try: # 0.12+ |
---|
158 | from trac.core import Component, implements |
---|
159 | from trac.versioncontrol.api import IRepositoryConnector, \ |
---|
160 | IRepositoryProvider |
---|
161 | class DummyRepos(Component): |
---|
162 | implements(IRepositoryConnector, IRepositoryProvider) |
---|
163 | def get_supported_types(self): |
---|
164 | yield ('dummy', 9) |
---|
165 | def get_repository(this, repos_type, repos_dir, params): |
---|
166 | return self.repos # Note: 'this' vs 'self' usage |
---|
167 | def get_repositories(self): |
---|
168 | yield ('', {'dir': 'dummy_dir', 'type': 'dummy'}) |
---|
169 | self.dummy = DummyRepos |
---|
170 | except ImportError: |
---|
171 | self.dummy = None # not supported, will use get_repository() |
---|
172 | |
---|
173 | def tearDown(self): |
---|
174 | if self.dummy: # remove from components list + interfaces dict |
---|
175 | self.env.__metaclass__._components.remove(self.dummy) |
---|
176 | for key in self.env.__metaclass__._registry.keys(): |
---|
177 | if self.dummy in self.env.__metaclass__._registry[key]: |
---|
178 | self.env.__metaclass__._registry[key].remove(self.dummy) |
---|
179 | shutil.rmtree(self.env.path) |
---|
180 | |
---|
181 | def test_get_build_for_slave(self): |
---|
182 | """ |
---|
183 | Make sure that a pending build of an activated configuration is |
---|
184 | scheduled for a slave that matches the target platform. |
---|
185 | """ |
---|
186 | BuildConfig(self.env, 'test', active=True).insert() |
---|
187 | platform = TargetPlatform(self.env, config='test', name='Foo') |
---|
188 | platform.insert() |
---|
189 | build = Build(self.env, config='test', platform=platform.id, rev=123, |
---|
190 | rev_time=42, status=Build.PENDING) |
---|
191 | build.insert() |
---|
192 | build_id = build.id |
---|
193 | |
---|
194 | queue = BuildQueue(self.env) |
---|
195 | build = queue.get_build_for_slave('foobar', {}) |
---|
196 | self.assertEqual(build_id, build.id) |
---|
197 | |
---|
198 | def test_next_pending_build_no_matching_slave(self): |
---|
199 | """ |
---|
200 | Make sure that builds for which there is no slave matching the target |
---|
201 | platform are not scheduled. |
---|
202 | """ |
---|
203 | BuildConfig(self.env, 'test', active=True).insert() |
---|
204 | build = Build(self.env, config='test', platform=1, rev=123, rev_time=42, |
---|
205 | status=Build.PENDING) |
---|
206 | build.insert() |
---|
207 | build_id = build.id |
---|
208 | |
---|
209 | queue = BuildQueue(self.env) |
---|
210 | build = queue.get_build_for_slave('foobar', {}) |
---|
211 | self.assertEqual(None, build) |
---|
212 | |
---|
213 | def test_next_pending_build_inactive_config(self): |
---|
214 | """ |
---|
215 | Make sure that builds for a deactived build config are not scheduled. |
---|
216 | """ |
---|
217 | BuildConfig(self.env, 'test').insert() |
---|
218 | platform = TargetPlatform(self.env, config='test', name='Foo') |
---|
219 | platform.insert() |
---|
220 | build = Build(self.env, config='test', platform=platform.id, rev=123, |
---|
221 | rev_time=42, status=Build.PENDING) |
---|
222 | build.insert() |
---|
223 | |
---|
224 | queue = BuildQueue(self.env) |
---|
225 | build = queue.get_build_for_slave('foobar', {}) |
---|
226 | self.assertEqual(None, build) |
---|
227 | |
---|
228 | def test_populate_not_build_all(self): |
---|
229 | self.repos.get_changeset = lambda rev: Mock( |
---|
230 | date=to_datetime(rev * 1000, utc)) |
---|
231 | self.repos.get_node = lambda path, rev=None: Mock( |
---|
232 | get_entries=lambda: [Mock(), Mock()], |
---|
233 | get_history=lambda: [('somepath', 123, 'edit'), |
---|
234 | ('somepath', 121, 'edit'), |
---|
235 | ('somepath', 120, 'edit')]) |
---|
236 | self.repos.normalize_path=lambda path: path |
---|
237 | self.repos.rev_older_than=lambda rev1, rev2: rev1 < rev2 |
---|
238 | |
---|
239 | BuildConfig(self.env, 'test', path='somepath', active=True).insert() |
---|
240 | platform1 = TargetPlatform(self.env, config='test', name='P1') |
---|
241 | platform1.insert() |
---|
242 | platform2 = TargetPlatform(self.env, config='test', name='P2') |
---|
243 | platform2.insert() |
---|
244 | |
---|
245 | queue = BuildQueue(self.env) |
---|
246 | queue.populate() |
---|
247 | queue.populate() |
---|
248 | queue.populate() |
---|
249 | |
---|
250 | builds = list(Build.select(self.env, config='test')) |
---|
251 | builds.sort(lambda a, b: cmp(a.platform, b.platform)) |
---|
252 | self.assertEqual(2, len(builds)) |
---|
253 | self.assertEqual(platform1.id, builds[0].platform) |
---|
254 | self.assertEqual('123', builds[0].rev) |
---|
255 | self.assertEqual(platform2.id, builds[1].platform) |
---|
256 | self.assertEqual('123', builds[1].rev) |
---|
257 | |
---|
258 | def test_populate_build_all(self): |
---|
259 | self.repos.get_changeset=lambda rev: Mock( |
---|
260 | date=to_datetime(rev * 1000, utc)) |
---|
261 | self.repos.get_node=lambda path, rev=None: Mock( |
---|
262 | get_entries=lambda: [Mock(), Mock()], |
---|
263 | get_history=lambda: [('somepath', 123, 'edit'), |
---|
264 | ('somepath', 121, 'edit'), |
---|
265 | ('somepath', 120, 'edit')]) |
---|
266 | self.repos.normalize_path=lambda path: path |
---|
267 | self.repos.rev_older_than=lambda rev1, rev2: rev1 < rev2 |
---|
268 | |
---|
269 | BuildConfig(self.env, 'test', path='somepath', active=True).insert() |
---|
270 | platform1 = TargetPlatform(self.env, config='test', name='P1') |
---|
271 | platform1.insert() |
---|
272 | platform2 = TargetPlatform(self.env, config='test', name='P2') |
---|
273 | platform2.insert() |
---|
274 | |
---|
275 | queue = BuildQueue(self.env, build_all=True) |
---|
276 | queue.populate() |
---|
277 | queue.populate() |
---|
278 | queue.populate() |
---|
279 | |
---|
280 | builds = list(Build.select(self.env, config='test')) |
---|
281 | builds.sort(lambda a, b: cmp(a.platform, b.platform)) |
---|
282 | self.assertEqual(6, len(builds)) |
---|
283 | self.assertEqual(platform1.id, builds[0].platform) |
---|
284 | self.assertEqual('123', builds[0].rev) |
---|
285 | self.assertEqual(platform1.id, builds[1].platform) |
---|
286 | self.assertEqual('121', builds[1].rev) |
---|
287 | self.assertEqual(platform1.id, builds[2].platform) |
---|
288 | self.assertEqual('120', builds[2].rev) |
---|
289 | self.assertEqual(platform2.id, builds[3].platform) |
---|
290 | self.assertEqual('123', builds[3].rev) |
---|
291 | self.assertEqual(platform2.id, builds[4].platform) |
---|
292 | self.assertEqual('121', builds[4].rev) |
---|
293 | self.assertEqual(platform2.id, builds[5].platform) |
---|
294 | self.assertEqual('120', builds[5].rev) |
---|
295 | |
---|
296 | def test_populate_thread_race_condition(self): |
---|
297 | messages = [] |
---|
298 | self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) |
---|
299 | def get_history(): |
---|
300 | yield ('somepath', 123, 'edit') |
---|
301 | yield ('somepath', 121, 'edit') |
---|
302 | yield ('somepath', 120, 'edit') |
---|
303 | time.sleep(1) # sleep to make sure both threads collect |
---|
304 | self.repos.get_changeset=lambda rev: Mock( |
---|
305 | date=to_datetime(rev * 1000, utc)) |
---|
306 | self.repos.get_node=lambda path, rev=None: Mock( |
---|
307 | get_entries=lambda: [Mock(), Mock()], |
---|
308 | get_history=get_history) |
---|
309 | self.repos.normalize_path=lambda path: path |
---|
310 | self.repos.rev_older_than=lambda rev1, rev2: rev1 < rev2 |
---|
311 | |
---|
312 | BuildConfig(self.env, 'test', path='somepath', active=True).insert() |
---|
313 | platform1 = TargetPlatform(self.env, config='test', name='P1') |
---|
314 | platform1.insert() |
---|
315 | platform2 = TargetPlatform(self.env, config='test', name='P2') |
---|
316 | platform2.insert() |
---|
317 | |
---|
318 | def build_populator(): |
---|
319 | queue = BuildQueue(self.env, build_all=True) |
---|
320 | queue.populate() |
---|
321 | |
---|
322 | thread1 = threading.Thread(target=build_populator) |
---|
323 | thread2 = threading.Thread(target=build_populator) |
---|
324 | # tiny sleep is to avoid odd segementation faults |
---|
325 | # (on Linux) and bus errors (on Mac OS X) |
---|
326 | thread1.start(); time.sleep(0.01); thread2.start() |
---|
327 | thread1.join(); thread2.join() |
---|
328 | |
---|
329 | # check builds got added |
---|
330 | builds = list(Build.select(self.env, config='test')) |
---|
331 | builds.sort(lambda a, b: cmp(a.platform, b.platform)) |
---|
332 | self.assertEqual(6, len(builds)) |
---|
333 | self.assertEqual(platform1.id, builds[0].platform) |
---|
334 | self.assertEqual('123', builds[0].rev) |
---|
335 | self.assertEqual(platform1.id, builds[1].platform) |
---|
336 | self.assertEqual('121', builds[1].rev) |
---|
337 | self.assertEqual(platform1.id, builds[2].platform) |
---|
338 | self.assertEqual('120', builds[2].rev) |
---|
339 | self.assertEqual(platform2.id, builds[3].platform) |
---|
340 | self.assertEqual('123', builds[3].rev) |
---|
341 | self.assertEqual(platform2.id, builds[4].platform) |
---|
342 | self.assertEqual('121', builds[4].rev) |
---|
343 | self.assertEqual(platform2.id, builds[5].platform) |
---|
344 | self.assertEqual('120', builds[5].rev) |
---|
345 | |
---|
346 | # check attempts at duplicate inserts were logged. |
---|
347 | failure_messages = [x for x in messages if x.startswith('Failed to insert build')] |
---|
348 | self.assertEqual(6, len(failure_messages)) |
---|
349 | |
---|
350 | def test_should_delete_build_platform_dont_exist(self): |
---|
351 | messages = [] |
---|
352 | self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) |
---|
353 | config = BuildConfig(self.env, 'test', active=True) |
---|
354 | config.insert() |
---|
355 | build = Build(self.env, config=config.name, rev=42, |
---|
356 | platform="no-stuff", rev_time=123456) |
---|
357 | build.insert() |
---|
358 | queue = BuildQueue(self.env, build_all=True) |
---|
359 | |
---|
360 | self.assertEqual(True, queue.should_delete_build(build, self.repos)) |
---|
361 | self.assert_("platform no longer exists" in messages[0]) |
---|
362 | |
---|
363 | def test_should_delete_build_config_deactivated(self): |
---|
364 | messages = [] |
---|
365 | self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) |
---|
366 | config = BuildConfig(self.env, 'test', active=False) |
---|
367 | config.insert() |
---|
368 | platform = TargetPlatform(self.env, config='test', name='stuff') |
---|
369 | platform.insert() |
---|
370 | build = Build(self.env, config=config.name, rev=42, |
---|
371 | platform=platform.id, rev_time=123456) |
---|
372 | build.insert() |
---|
373 | queue = BuildQueue(self.env, build_all=True) |
---|
374 | |
---|
375 | self.assertEqual(True, queue.should_delete_build(build, self.repos)) |
---|
376 | self.assert_("configuration is deactivated" in messages[0]) |
---|
377 | |
---|
378 | def test_should_delete_build_config_none(self): |
---|
379 | out = [] |
---|
380 | self.env.log = Mock( |
---|
381 | info=lambda msg, *args: out.extend([msg] + list(args))) |
---|
382 | platform = TargetPlatform(self.env, config='test', name='stuff') |
---|
383 | platform.insert() |
---|
384 | build = Build(self.env, config='does_not_exist', rev=42, |
---|
385 | platform=platform.id, rev_time=123456) |
---|
386 | build.insert() |
---|
387 | queue = BuildQueue(self.env, build_all=True) |
---|
388 | |
---|
389 | self.assertEqual(True, queue.should_delete_build(build, self.repos)) |
---|
390 | self.assertTrue("configuration is deactivated" in out[0]) |
---|
391 | self.assertEquals('unknown config "does_not_exist"', out[1]) |
---|
392 | |
---|
393 | def test_should_delete_build_outside_revision_range(self): |
---|
394 | messages = [] |
---|
395 | self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) |
---|
396 | self.repos.rev_older_than = lambda rev1, rev2: rev1 < rev2 |
---|
397 | config = BuildConfig(self.env, 'test', active=True, min_rev=120, |
---|
398 | max_rev=123) |
---|
399 | config.insert() |
---|
400 | platform = TargetPlatform(self.env, config='test', name='stuff') |
---|
401 | platform.insert() |
---|
402 | build1 = Build(self.env, config=config.name, rev=42, |
---|
403 | platform=platform.id, rev_time=123456) |
---|
404 | build1.insert() |
---|
405 | build2 = Build(self.env, config=config.name, rev=10042, |
---|
406 | platform=platform.id, rev_time=123456) |
---|
407 | build2.insert() |
---|
408 | queue = BuildQueue(self.env, build_all=True) |
---|
409 | |
---|
410 | self.assertEqual(True, queue.should_delete_build(build1, self.repos)) |
---|
411 | self.assertEqual(True, queue.should_delete_build(build2, self.repos)) |
---|
412 | self.assert_("outside of the revision range" in messages[0]) |
---|
413 | self.assert_("outside of the revision range" in messages[1]) |
---|
414 | |
---|
415 | def test_should_delete_build_old_with_not_buildall(self): |
---|
416 | messages = [] |
---|
417 | self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) |
---|
418 | config = BuildConfig(self.env, 'test', active=True) |
---|
419 | config.insert() |
---|
420 | platform = TargetPlatform(self.env, config='test', name='stuff') |
---|
421 | platform.insert() |
---|
422 | build1 = Build(self.env, config=config.name, rev=42, |
---|
423 | platform=platform.id, rev_time=123456) |
---|
424 | build1.insert() |
---|
425 | build2 = Build(self.env, config=config.name, rev=43, |
---|
426 | platform=platform.id, rev_time=123457, |
---|
427 | slave='slave') |
---|
428 | build2.insert() |
---|
429 | queue = BuildQueue(self.env, build_all=False) |
---|
430 | |
---|
431 | self.assertEqual(True, queue.should_delete_build(build1, self.repos)) |
---|
432 | self.assert_("more recent build exists" in messages[0]) |
---|
433 | |
---|
434 | def test_reset_orphaned_builds(self): |
---|
435 | BuildConfig(self.env, 'test').insert() |
---|
436 | platform = TargetPlatform(self.env, config='test', name='Foo') |
---|
437 | platform.insert() |
---|
438 | build1 = Build(self.env, config='test', platform=platform.id, rev=123, |
---|
439 | rev_time=42, status=Build.IN_PROGRESS, slave='heinz', |
---|
440 | last_activity=time.time() - 600) # active ten minutes ago |
---|
441 | build1.insert() |
---|
442 | |
---|
443 | build2 = Build(self.env, config='test', platform=platform.id, rev=124, |
---|
444 | rev_time=42, status=Build.IN_PROGRESS, slave='heinz', |
---|
445 | last_activity=time.time() - 60) # active a minute ago |
---|
446 | build2.insert() |
---|
447 | |
---|
448 | queue = BuildQueue(self.env, timeout=300) # 5 minutes timeout |
---|
449 | build = queue.reset_orphaned_builds() |
---|
450 | self.assertEqual(Build.PENDING, Build.fetch(self.env, build1.id).status) |
---|
451 | self.assertEqual(Build.IN_PROGRESS, |
---|
452 | Build.fetch(self.env, build2.id).status) |
---|
453 | |
---|
454 | def test_match_slave_match(self): |
---|
455 | BuildConfig(self.env, 'test', active=True).insert() |
---|
456 | platform = TargetPlatform(self.env, config='test', name="Unix") |
---|
457 | platform.rules.append(('family', 'posix')) |
---|
458 | platform.insert() |
---|
459 | platform_id = platform.id |
---|
460 | |
---|
461 | queue = BuildQueue(self.env) |
---|
462 | platforms = queue.match_slave('foo', {'family': 'posix'}) |
---|
463 | self.assertEqual(1, len(platforms)) |
---|
464 | self.assertEqual(platform_id, platforms[0].id) |
---|
465 | |
---|
466 | def test_register_slave_match_simple_fail(self): |
---|
467 | BuildConfig(self.env, 'test', active=True).insert() |
---|
468 | platform = TargetPlatform(self.env, config='test', name="Unix") |
---|
469 | platform.rules.append(('family', 'posix')) |
---|
470 | platform.insert() |
---|
471 | |
---|
472 | queue = BuildQueue(self.env) |
---|
473 | platforms = queue.match_slave('foo', {'family': 'nt'}) |
---|
474 | self.assertEqual([], platforms) |
---|
475 | |
---|
476 | def test_register_slave_match_case_insensitive(self): |
---|
477 | BuildConfig(self.env, 'test', active=True).insert() |
---|
478 | platform = TargetPlatform(self.env, config='test', name="Unix") |
---|
479 | platform.rules.append(('os', 'LiNUX')) |
---|
480 | platform.insert() |
---|
481 | platform_id = platform.id |
---|
482 | |
---|
483 | queue = BuildQueue(self.env) |
---|
484 | platforms = queue.match_slave('foo', {'os': 'linux'}) |
---|
485 | self.assertEqual(1, len(platforms)) |
---|
486 | self.assertEqual(platform_id, platforms[0].id) |
---|
487 | |
---|
488 | def test_register_slave_match_regexp(self): |
---|
489 | BuildConfig(self.env, 'test', active=True).insert() |
---|
490 | platform = TargetPlatform(self.env, config='test', name="Unix") |
---|
491 | platform.rules.append(('version', '8\.\d\.\d')) |
---|
492 | platform.insert() |
---|
493 | platform_id = platform.id |
---|
494 | |
---|
495 | queue = BuildQueue(self.env) |
---|
496 | platforms = queue.match_slave('foo', {'version': '8.2.0'}) |
---|
497 | self.assertEqual(1, len(platforms)) |
---|
498 | self.assertEqual(platform_id, platforms[0].id) |
---|
499 | |
---|
500 | def test_register_slave_match_regexp_multi(self): |
---|
501 | BuildConfig(self.env, 'test', active=True).insert() |
---|
502 | platform = TargetPlatform(self.env, config='test', name="Unix") |
---|
503 | platform.rules.append(('os', '^Linux')) |
---|
504 | platform.rules.append(('processor', '^[xi]\d?86$')) |
---|
505 | platform.insert() |
---|
506 | platform_id = platform.id |
---|
507 | |
---|
508 | queue = BuildQueue(self.env) |
---|
509 | platforms = queue.match_slave('foo', {'os': 'Linux', 'processor': 'i686'}) |
---|
510 | self.assertEqual(1, len(platforms)) |
---|
511 | self.assertEqual(platform_id, platforms[0].id) |
---|
512 | |
---|
513 | def test_register_slave_match_regexp_fail(self): |
---|
514 | BuildConfig(self.env, 'test', active=True).insert() |
---|
515 | platform = TargetPlatform(self.env, config='test', name="Unix") |
---|
516 | platform.rules.append(('version', '8\.\d\.\d')) |
---|
517 | platform.insert() |
---|
518 | |
---|
519 | queue = BuildQueue(self.env) |
---|
520 | platforms = queue.match_slave('foo', {'version': '7.8.1'}) |
---|
521 | self.assertEqual([], platforms) |
---|
522 | |
---|
523 | def test_register_slave_match_regexp_invalid(self): |
---|
524 | BuildConfig(self.env, 'test', active=True).insert() |
---|
525 | platform = TargetPlatform(self.env, config='test', name="Unix") |
---|
526 | platform.rules.append(('version', '8(\.\d')) |
---|
527 | platform.insert() |
---|
528 | |
---|
529 | queue = BuildQueue(self.env) |
---|
530 | platforms = queue.match_slave('foo', {'version': '7.8.1'}) |
---|
531 | self.assertEqual([], platforms) |
---|
532 | |
---|
533 | |
---|
534 | def suite(): |
---|
535 | suite = unittest.TestSuite() |
---|
536 | suite.addTest(unittest.makeSuite(CollectChangesTestCase, 'test')) |
---|
537 | suite.addTest(unittest.makeSuite(BuildQueueTestCase, 'test')) |
---|
538 | return suite |
---|
539 | |
---|
540 | if __name__ == '__main__': |
---|
541 | unittest.main(defaultTest='suite') |
---|