annotate bitten/tests/queue.py @ 893:ed77e3e1c43f

BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
author osimons
date Tue, 08 Mar 2011 03:19:17 +0000
parents 7c80375d4817
children 0cf576cea845
rev   line source
379
0df178e07fdb Use UTF-8 as encoding of source files.
cmlenz
parents: 366
diff changeset
1 # -*- coding: utf-8 -*-
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
2 #
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 392
diff changeset
3 # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
832
7c80375d4817 Updated copyright to 2010.
osimons
parents: 830
diff changeset
4 # Copyright (C) 2007-2010 Edgewall Software
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
5 # All rights reserved.
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
6 #
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
7 # This software is licensed as described in the file COPYING, which
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
8 # you should have received as part of this distribution. The terms
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 392
diff changeset
9 # are also available at http://bitten.edgewall.org/wiki/License.
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
10
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
11 import os
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
12 import shutil
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
13 import tempfile
650
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
14 import threading
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
15 import time
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
16 import unittest
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
17
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
18 from trac.db import DatabaseManager
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
19 from trac.test import EnvironmentStub, Mock
585
87de4513bfdd 0.6dev: Cleaning remaining 'frontend' datetime code - at least down to all code that interface with the various `model` classes that still only works with timestamps for input and output. See #85.
osimons
parents: 462
diff changeset
20 from trac.util.datefmt import to_datetime, utc
436
cfbc9ee622d5 Finish the move of build configuration management into the admin interface.
cmlenz
parents: 419
diff changeset
21 from bitten.model import BuildConfig, TargetPlatform, Build, schema
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
22 from bitten.queue import BuildQueue, collect_changes
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
23
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
24
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
25 class CollectChangesTestCase(unittest.TestCase):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
26 """
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
27 Unit tests for the `bitten.queue.collect_changes` function.
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
28 """
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
29
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
30 def setUp(self):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
31 self.env = EnvironmentStub()
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
32 self.env.path = tempfile.mkdtemp()
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
33
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
34 db = self.env.get_db_cnx()
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
35 cursor = db.cursor()
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
36 connector, _ = DatabaseManager(self.env)._get_connector()
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
37 for table in schema:
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
38 for stmt in connector.to_sql(table):
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
39 cursor.execute(stmt)
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
40
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
41 self.config = BuildConfig(self.env, name='test', path='somepath')
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
42 self.config.insert(db=db)
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
43 self.platform = TargetPlatform(self.env, config='test', name='Foo')
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
44 self.platform.insert(db=db)
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
45 db.commit()
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
46
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
47 def tearDown(self):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
48 shutil.rmtree(self.env.path)
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
49
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
50 def test_stop_on_copy(self):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
51 self.env.get_repository = lambda authname=None: Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
52 get_node=lambda path, rev=None: Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
53 get_history=lambda: [('otherpath', 123, 'copy')]
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
54 ),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
55 normalize_path=lambda path: path
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
56 )
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
57
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
58 retval = list(collect_changes(self.env.get_repository(), self.config))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
59 self.assertEqual(0, len(retval))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
60
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
61 def test_stop_on_minrev(self):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
62 self.env.get_repository = lambda authname=None: Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
63 get_node=lambda path, rev=None: Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
64 get_entries=lambda: [Mock(), Mock()],
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
65 get_history=lambda: [('somepath', 123, 'edit'),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
66 ('somepath', 121, 'edit'),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
67 ('somepath', 120, 'edit')]
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
68 ),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
69 normalize_path=lambda path: path,
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
70 rev_older_than=lambda rev1, rev2: rev1 < rev2
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
71 )
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
72
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
73 self.config.min_rev = 123
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
74 self.config.update()
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
75
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
76 retval = list(collect_changes(self.env.get_repository(), self.config))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
77 self.assertEqual(1, len(retval))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
78 self.assertEqual(123, retval[0][1])
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
79
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
80 def test_skip_until_maxrev(self):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
81 self.env.get_repository = lambda authname=None: Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
82 get_node=lambda path, rev=None: Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
83 get_entries=lambda: [Mock(), Mock()],
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
84 get_history=lambda: [('somepath', 123, 'edit'),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
85 ('somepath', 121, 'edit'),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
86 ('somepath', 120, 'edit')]
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
87 ),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
88 normalize_path=lambda path: path,
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
89 rev_older_than=lambda rev1, rev2: rev1 < rev2
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
90 )
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
91
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
92 self.config.max_rev=121
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
93 self.config.update()
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
94
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
95 retval = list(collect_changes(self.env.get_repository(), self.config))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
96 self.assertEqual(2, len(retval))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
97 self.assertEqual(121, retval[0][1])
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
98 self.assertEqual(120, retval[1][1])
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
99
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
100 def test_skip_empty_dir(self):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
101 def _mock_get_node(path, rev=None):
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
102 if rev and rev == 121:
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
103 return Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
104 get_entries=lambda: []
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
105 )
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
106 else:
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
107 return Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
108 get_entries=lambda: [Mock(), Mock()],
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
109 get_history=lambda: [('somepath', 123, 'edit'),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
110 ('somepath', 121, 'edit'),
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
111 ('somepath', 120, 'edit')]
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
112 )
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
113
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
114 self.env.get_repository = lambda authname=None: Mock(
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
115 get_node=_mock_get_node,
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
116 normalize_path=lambda path: path,
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
117 rev_older_than=lambda rev1, rev2: rev1 < rev2
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
118 )
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
119
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
120 retval = list(collect_changes(self.env.get_repository(), self.config))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
121 self.assertEqual(2, len(retval))
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
122 self.assertEqual(123, retval[0][1])
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
123 self.assertEqual(120, retval[1][1])
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
124
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
125
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
126 class BuildQueueTestCase(unittest.TestCase):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
127
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
128 def setUp(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
129 self.env = EnvironmentStub()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
130 self.env.path = tempfile.mkdtemp()
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
131
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
132 db = self.env.get_db_cnx()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
133 cursor = db.cursor()
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
134 connector, _ = DatabaseManager(self.env)._get_connector()
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
135 for table in schema:
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents: 408
diff changeset
136 for stmt in connector.to_sql(table):
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
137 cursor.execute(stmt)
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
138 db.commit()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
139
366
18a06917871f Use dummy repository in queue unit tests.
cmlenz
parents: 364
diff changeset
140 # Hook up a dummy repository
18a06917871f Use dummy repository in queue unit tests.
cmlenz
parents: 364
diff changeset
141 self.repos = Mock()
18a06917871f Use dummy repository in queue unit tests.
cmlenz
parents: 364
diff changeset
142 self.env.get_repository = lambda authname=None: self.repos
18a06917871f Use dummy repository in queue unit tests.
cmlenz
parents: 364
diff changeset
143
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
144 def tearDown(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
145 shutil.rmtree(self.env.path)
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
146
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
147 def test_get_build_for_slave(self):
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
148 """
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
149 Make sure that a pending build of an activated configuration is
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
150 scheduled for a slave that matches the target platform.
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
151 """
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
152 BuildConfig(self.env, 'test', active=True).insert()
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
153 platform = TargetPlatform(self.env, config='test', name='Foo')
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
154 platform.insert()
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
155 build = Build(self.env, config='test', platform=platform.id, rev=123,
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
156 rev_time=42, status=Build.PENDING)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
157 build.insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
158 build_id = build.id
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
159
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
160 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
161 build = queue.get_build_for_slave('foobar', {})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
162 self.assertEqual(build_id, build.id)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
163
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
164 def test_next_pending_build_no_matching_slave(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
165 """
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
166 Make sure that builds for which there is no slave matching the target
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
167 platform are not scheduled.
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
168 """
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
169 BuildConfig(self.env, 'test', active=True).insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
170 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42,
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
171 status=Build.PENDING)
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
172 build.insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
173 build_id = build.id
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
174
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
175 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
176 build = queue.get_build_for_slave('foobar', {})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
177 self.assertEqual(None, build)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
178
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
179 def test_next_pending_build_inactive_config(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
180 """
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
181 Make sure that builds for a deactived build config are not scheduled.
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
182 """
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
183 BuildConfig(self.env, 'test').insert()
384
dff1cde945aa Fix unit test in build queue tests.
cmlenz
parents: 379
diff changeset
184 platform = TargetPlatform(self.env, config='test', name='Foo')
dff1cde945aa Fix unit test in build queue tests.
cmlenz
parents: 379
diff changeset
185 platform.insert()
dff1cde945aa Fix unit test in build queue tests.
cmlenz
parents: 379
diff changeset
186 build = Build(self.env, config='test', platform=platform.id, rev=123,
dff1cde945aa Fix unit test in build queue tests.
cmlenz
parents: 379
diff changeset
187 rev_time=42, status=Build.PENDING)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
188 build.insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
189
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
190 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
191 build = queue.get_build_for_slave('foobar', {})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
192 self.assertEqual(None, build)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
193
804
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
194 def test_populate_no_repos(self):
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
195 """
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
196 Cannot work when there are no repositories defined.
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
197 """
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
198 self.env.get_repository = lambda: None
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
199 queue = BuildQueue(self.env)
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
200 self.assertRaises(AssertionError, queue.populate)
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
201
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
202 def test_populate_not_build_all(self):
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
203 self.env.get_repository = lambda authname=None: Mock(
585
87de4513bfdd 0.6dev: Cleaning remaining 'frontend' datetime code - at least down to all code that interface with the various `model` classes that still only works with timestamps for input and output. See #85.
osimons
parents: 462
diff changeset
204 get_changeset=lambda rev: Mock(date=to_datetime(rev * 1000, utc)),
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
205 get_node=lambda path, rev=None: Mock(
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
206 get_entries=lambda: [Mock(), Mock()],
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
207 get_history=lambda: [('somepath', 123, 'edit'),
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
208 ('somepath', 121, 'edit'),
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
209 ('somepath', 120, 'edit')]
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
210 ),
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
211 normalize_path=lambda path: path,
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
212 rev_older_than=lambda rev1, rev2: rev1 < rev2
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
213 )
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
214 BuildConfig(self.env, 'test', path='somepath', active=True).insert()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
215 platform1 = TargetPlatform(self.env, config='test', name='P1')
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
216 platform1.insert()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
217 platform2 = TargetPlatform(self.env, config='test', name='P2')
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
218 platform2.insert()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
219
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
220 queue = BuildQueue(self.env)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
221 queue.populate()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
222 queue.populate()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
223 queue.populate()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
224
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
225 builds = list(Build.select(self.env, config='test'))
462
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
226 builds.sort(lambda a, b: cmp(a.platform, b.platform))
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
227 self.assertEqual(2, len(builds))
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
228 self.assertEqual(platform1.id, builds[0].platform)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
229 self.assertEqual('123', builds[0].rev)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
230 self.assertEqual(platform2.id, builds[1].platform)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
231 self.assertEqual('123', builds[1].rev)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
232
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
233 def test_populate_build_all(self):
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
234 self.env.get_repository = lambda authname=None: Mock(
585
87de4513bfdd 0.6dev: Cleaning remaining 'frontend' datetime code - at least down to all code that interface with the various `model` classes that still only works with timestamps for input and output. See #85.
osimons
parents: 462
diff changeset
235 get_changeset=lambda rev: Mock(date=to_datetime(rev * 1000, utc)),
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
236 get_node=lambda path, rev=None: Mock(
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
237 get_entries=lambda: [Mock(), Mock()],
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
238 get_history=lambda: [('somepath', 123, 'edit'),
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
239 ('somepath', 121, 'edit'),
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
240 ('somepath', 120, 'edit')]
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
241 ),
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
242 normalize_path=lambda path: path,
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
243 rev_older_than=lambda rev1, rev2: rev1 < rev2
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
244 )
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
245 BuildConfig(self.env, 'test', path='somepath', active=True).insert()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
246 platform1 = TargetPlatform(self.env, config='test', name='P1')
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
247 platform1.insert()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
248 platform2 = TargetPlatform(self.env, config='test', name='P2')
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
249 platform2.insert()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
250
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
251 queue = BuildQueue(self.env, build_all=True)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
252 queue.populate()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
253 queue.populate()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
254 queue.populate()
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
255
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
256 builds = list(Build.select(self.env, config='test'))
462
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
257 builds.sort(lambda a, b: cmp(a.platform, b.platform))
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
258 self.assertEqual(6, len(builds))
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
259 self.assertEqual(platform1.id, builds[0].platform)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
260 self.assertEqual('123', builds[0].rev)
462
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
261 self.assertEqual(platform1.id, builds[1].platform)
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
262 self.assertEqual('121', builds[1].rev)
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
263 self.assertEqual(platform1.id, builds[2].platform)
462
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
264 self.assertEqual('120', builds[2].rev)
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
265 self.assertEqual(platform2.id, builds[3].platform)
462
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
266 self.assertEqual('123', builds[3].rev)
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
267 self.assertEqual(platform2.id, builds[4].platform)
8d7091819913 Fixed the sorting of builds in the unit tests added in [497].
cmlenz
parents: 450
diff changeset
268 self.assertEqual('121', builds[4].rev)
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
269 self.assertEqual(platform2.id, builds[5].platform)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
270 self.assertEqual('120', builds[5].rev)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 436
diff changeset
271
650
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
272 def test_populate_thread_race_condition(self):
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
273 messages = []
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
274 self.env.log = Mock(info=lambda msg, *args: messages.append(msg))
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
275 def get_history():
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
276 yield ('somepath', 123, 'edit')
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
277 yield ('somepath', 121, 'edit')
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
278 yield ('somepath', 120, 'edit')
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
279 time.sleep(1) # sleep to make sure both threads collect
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
280 self.env.get_repository = lambda authname=None: Mock(
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
281 get_changeset=lambda rev: Mock(date=to_datetime(rev * 1000, utc)),
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
282 get_node=lambda path, rev=None: Mock(
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
283 get_entries=lambda: [Mock(), Mock()],
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
284 get_history=get_history
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
285 ),
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
286 normalize_path=lambda path: path,
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
287 rev_older_than=lambda rev1, rev2: rev1 < rev2
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
288 )
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
289 BuildConfig(self.env, 'test', path='somepath', active=True).insert()
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
290 platform1 = TargetPlatform(self.env, config='test', name='P1')
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
291 platform1.insert()
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
292 platform2 = TargetPlatform(self.env, config='test', name='P2')
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
293 platform2.insert()
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
294
665
177d52932d03 0.6dev: Simpler threading implementation in the queue populate race-condition test.
osimons
parents: 650
diff changeset
295 def build_populator():
177d52932d03 0.6dev: Simpler threading implementation in the queue populate race-condition test.
osimons
parents: 650
diff changeset
296 queue = BuildQueue(self.env, build_all=True)
177d52932d03 0.6dev: Simpler threading implementation in the queue populate race-condition test.
osimons
parents: 650
diff changeset
297 queue.populate()
177d52932d03 0.6dev: Simpler threading implementation in the queue populate race-condition test.
osimons
parents: 650
diff changeset
298
177d52932d03 0.6dev: Simpler threading implementation in the queue populate race-condition test.
osimons
parents: 650
diff changeset
299 thread1 = threading.Thread(target=build_populator)
177d52932d03 0.6dev: Simpler threading implementation in the queue populate race-condition test.
osimons
parents: 650
diff changeset
300 thread2 = threading.Thread(target=build_populator)
698
86e946ced5a0 Separate thread start times slightly to avoid odd errors (not ideal but it avoids this test failing for reasons unrelated to what it's testing).
hodgestar
parents: 665
diff changeset
301 # tiny sleep is to avoid odd segementation faults
86e946ced5a0 Separate thread start times slightly to avoid odd errors (not ideal but it avoids this test failing for reasons unrelated to what it's testing).
hodgestar
parents: 665
diff changeset
302 # (on Linux) and bus errors (on Mac OS X)
86e946ced5a0 Separate thread start times slightly to avoid odd errors (not ideal but it avoids this test failing for reasons unrelated to what it's testing).
hodgestar
parents: 665
diff changeset
303 thread1.start(); time.sleep(0.01); thread2.start()
650
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
304 thread1.join(); thread2.join()
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
305
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
306 # check builds got added
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
307 builds = list(Build.select(self.env, config='test'))
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
308 builds.sort(lambda a, b: cmp(a.platform, b.platform))
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
309 self.assertEqual(6, len(builds))
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
310 self.assertEqual(platform1.id, builds[0].platform)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
311 self.assertEqual('123', builds[0].rev)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
312 self.assertEqual(platform1.id, builds[1].platform)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
313 self.assertEqual('121', builds[1].rev)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
314 self.assertEqual(platform1.id, builds[2].platform)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
315 self.assertEqual('120', builds[2].rev)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
316 self.assertEqual(platform2.id, builds[3].platform)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
317 self.assertEqual('123', builds[3].rev)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
318 self.assertEqual(platform2.id, builds[4].platform)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
319 self.assertEqual('121', builds[4].rev)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
320 self.assertEqual(platform2.id, builds[5].platform)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
321 self.assertEqual('120', builds[5].rev)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
322
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
323 # check attempts at duplicate inserts were logged.
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
324 failure_messages = [x for x in messages if x.startswith('Failed to insert build')]
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
325 self.assertEqual(6, len(failure_messages))
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 606
diff changeset
326
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
327 def test_should_delete_build_platform_dont_exist(self):
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
328 messages = []
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
329 self.env.log = Mock(info=lambda msg, *args: messages.append(msg))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
330 config = BuildConfig(self.env, 'test', active=True)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
331 config.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
332 build = Build(self.env, config=config.name, rev=42,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
333 platform="no-stuff", rev_time=123456)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
334 build.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
335 queue = BuildQueue(self.env, build_all=True)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
336
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
337 self.assertEqual(True, queue.should_delete_build(build, self.repos))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
338 self.assert_("platform no longer exists" in messages[0])
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
339
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
340 def test_should_delete_build_config_deactivated(self):
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
341 messages = []
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
342 self.env.log = Mock(info=lambda msg, *args: messages.append(msg))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
343 config = BuildConfig(self.env, 'test', active=False)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
344 config.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
345 platform = TargetPlatform(self.env, config='test', name='stuff')
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
346 platform.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
347 build = Build(self.env, config=config.name, rev=42,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
348 platform=platform.id, rev_time=123456)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
349 build.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
350 queue = BuildQueue(self.env, build_all=True)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
351
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
352 self.assertEqual(True, queue.should_delete_build(build, self.repos))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
353 self.assert_("configuration is deactivated" in messages[0])
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
354
893
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
355 def test_should_delete_build_config_none(self):
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
356 out = []
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
357 self.env.log = Mock(
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
358 info=lambda msg, *args: out.extend([msg] + list(args)))
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
359 platform = TargetPlatform(self.env, config='test', name='stuff')
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
360 platform.insert()
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
361 build = Build(self.env, config='does_not_exist', rev=42,
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
362 platform=platform.id, rev_time=123456)
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
363 build.insert()
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
364 queue = BuildQueue(self.env, build_all=True)
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
365
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
366 self.assertEqual(True, queue.should_delete_build(build, self.repos))
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
367 self.assertTrue("configuration is deactivated" in out[0])
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
368 self.assertEquals('unknown config "does_not_exist"', out[1])
ed77e3e1c43f BuildConfig may be `None` when checking to see if build should be deleted. Fix + test, closes #666.
osimons
parents: 832
diff changeset
369
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
370 def test_should_delete_build_outside_revision_range(self):
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
371 messages = []
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
372 self.env.log = Mock(info=lambda msg, *args: messages.append(msg))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
373 self.repos.rev_older_than = lambda rev1, rev2: rev1 < rev2
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
374 config = BuildConfig(self.env, 'test', active=True, min_rev=120,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
375 max_rev=123)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
376 config.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
377 platform = TargetPlatform(self.env, config='test', name='stuff')
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
378 platform.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
379 build1 = Build(self.env, config=config.name, rev=42,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
380 platform=platform.id, rev_time=123456)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
381 build1.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
382 build2 = Build(self.env, config=config.name, rev=10042,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
383 platform=platform.id, rev_time=123456)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
384 build2.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
385 queue = BuildQueue(self.env, build_all=True)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
386
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
387 self.assertEqual(True, queue.should_delete_build(build1, self.repos))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
388 self.assertEqual(True, queue.should_delete_build(build2, self.repos))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
389 self.assert_("outside of the revision range" in messages[0])
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
390 self.assert_("outside of the revision range" in messages[1])
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
391
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
392 def test_should_delete_build_old_with_not_buildall(self):
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
393 messages = []
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
394 self.env.log = Mock(info=lambda msg, *args: messages.append(msg))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
395 config = BuildConfig(self.env, 'test', active=True)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
396 config.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
397 platform = TargetPlatform(self.env, config='test', name='stuff')
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
398 platform.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
399 build1 = Build(self.env, config=config.name, rev=42,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
400 platform=platform.id, rev_time=123456)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
401 build1.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
402 build2 = Build(self.env, config=config.name, rev=43,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
403 platform=platform.id, rev_time=123457,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
404 slave='slave')
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
405 build2.insert()
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
406 queue = BuildQueue(self.env, build_all=False)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
407
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
408 self.assertEqual(True, queue.should_delete_build(build1, self.repos))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
409 self.assert_("more recent build exists" in messages[0])
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
410
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
411 def test_reset_orphaned_builds(self):
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
412 BuildConfig(self.env, 'test').insert()
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
413 platform = TargetPlatform(self.env, config='test', name='Foo')
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
414 platform.insert()
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
415 build1 = Build(self.env, config='test', platform=platform.id, rev=123,
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
416 rev_time=42, status=Build.IN_PROGRESS, slave='heinz',
762
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 698
diff changeset
417 last_activity=time.time() - 600) # active ten minutes ago
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
418 build1.insert()
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
420 build2 = Build(self.env, config='test', platform=platform.id, rev=124,
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
421 rev_time=42, status=Build.IN_PROGRESS, slave='heinz',
762
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 698
diff changeset
422 last_activity=time.time() - 60) # active a minute ago
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
423 build2.insert()
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
424
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
425 queue = BuildQueue(self.env, timeout=300) # 5 minutes timeout
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
426 build = queue.reset_orphaned_builds()
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
427 self.assertEqual(Build.PENDING, Build.fetch(self.env, build1.id).status)
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
428 self.assertEqual(Build.IN_PROGRESS,
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
429 Build.fetch(self.env, build2.id).status)
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 410
diff changeset
430
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
431 def test_match_slave_match(self):
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
432 BuildConfig(self.env, 'test', active=True).insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
433 platform = TargetPlatform(self.env, config='test', name="Unix")
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
434 platform.rules.append(('family', 'posix'))
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
435 platform.insert()
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
436 platform_id = platform.id
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
437
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
438 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
439 platforms = queue.match_slave('foo', {'family': 'posix'})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
440 self.assertEqual(1, len(platforms))
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
441 self.assertEqual(platform_id, platforms[0].id)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
442
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
443 def test_register_slave_match_simple_fail(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
444 BuildConfig(self.env, 'test', active=True).insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
445 platform = TargetPlatform(self.env, config='test', name="Unix")
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
446 platform.rules.append(('family', 'posix'))
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
447 platform.insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
448
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
449 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
450 platforms = queue.match_slave('foo', {'family': 'nt'})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
451 self.assertEqual([], platforms)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
452
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
453 def test_register_slave_match_regexp(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
454 BuildConfig(self.env, 'test', active=True).insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
455 platform = TargetPlatform(self.env, config='test', name="Unix")
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
456 platform.rules.append(('version', '8\.\d\.\d'))
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
457 platform.insert()
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
458 platform_id = platform.id
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
459
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
460 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
461 platforms = queue.match_slave('foo', {'version': '8.2.0'})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
462 self.assertEqual(1, len(platforms))
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
463 self.assertEqual(platform_id, platforms[0].id)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
464
259
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
465 def test_register_slave_match_regexp_multi(self):
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
466 BuildConfig(self.env, 'test', active=True).insert()
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
467 platform = TargetPlatform(self.env, config='test', name="Unix")
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
468 platform.rules.append(('os', '^Linux'))
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
469 platform.rules.append(('processor', '^[xi]\d?86$'))
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
470 platform.insert()
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
471 platform_id = platform.id
259
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
472
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
473 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
474 platforms = queue.match_slave('foo', {'os': 'Linux', 'processor': 'i686'})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
475 self.assertEqual(1, len(platforms))
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
476 self.assertEqual(platform_id, platforms[0].id)
259
f8e20eac7df4 Add unit test for multi-property target platform matching.
cmlenz
parents: 239
diff changeset
477
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
478 def test_register_slave_match_regexp_fail(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
479 BuildConfig(self.env, 'test', active=True).insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
480 platform = TargetPlatform(self.env, config='test', name="Unix")
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
481 platform.rules.append(('version', '8\.\d\.\d'))
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
482 platform.insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
483
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
484 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
485 platforms = queue.match_slave('foo', {'version': '7.8.1'})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
486 self.assertEqual([], platforms)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
487
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
488 def test_register_slave_match_regexp_invalid(self):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
489 BuildConfig(self.env, 'test', active=True).insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
490 platform = TargetPlatform(self.env, config='test', name="Unix")
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
491 platform.rules.append(('version', '8(\.\d'))
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
492 platform.insert()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
493
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
494 queue = BuildQueue(self.env)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
495 platforms = queue.match_slave('foo', {'version': '7.8.1'})
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 384
diff changeset
496 self.assertEqual([], platforms)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
497
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
498
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
499 def suite():
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
500 suite = unittest.TestSuite()
262
2c3a1dd67c09 Unit tests for `bitten.queue.collect_changes()`.
cmlenz
parents: 259
diff changeset
501 suite.addTest(unittest.makeSuite(CollectChangesTestCase, 'test'))
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
502 suite.addTest(unittest.makeSuite(BuildQueueTestCase, 'test'))
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
503 return suite
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
504
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
505 if __name__ == '__main__':
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
506 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software