This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_misc_nextslaves.py
81 lines (65 loc) · 3.25 KB
/
test_misc_nextslaves.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from __future__ import with_statement
import mock
from twisted.trial import unittest
import buildbotcustom.misc
from buildbotcustom.misc import _nextSlowIdleSlave, \
_nextFastSlave, _nextSlowSlave
class TestNextSlaveFuncs(unittest.TestCase):
def setUp(self):
# Reset these each time
buildbotcustom.misc.fastRegexes = ['fast']
self.slaves = slaves = []
for name in ('fast1', 'fast2', 'fast3', 'slow1', 'slow2', 'slow3'):
slave = mock.Mock()
slave.slave.slavename = name
slaves.append(slave)
self.slow_slaves = [
s for s in self.slaves if "slow" in s.slave.slavename]
self.fast_slaves = [
s for s in self.slaves if "fast" in s.slave.slavename]
self.builder = builder = mock.Mock()
builder.builder_status.buildCache.keys.return_value = []
builder.slaves = self.slaves
def test_nextFastSlave_AllAvail(self):
"""Test that _nextFastSlave returns a fast
slave when all slaves are available."""
slave = _nextFastSlave(self.builder, self.slaves, only_fast=True)
self.assert_(slave.slave.slavename.startswith("fast"))
def test_nextFastSlave_OnlySlowAvail(self):
"""Test that _nextFastSlave returns None slave when only slow slaves
are available, and only_fast is True."""
slave = _nextFastSlave(self.builder, self.slow_slaves, only_fast=True)
self.assert_(slave is None)
def test_nextFastSlave_OnlySlowAvail_notOnlyFast(self):
"""Test that _nextFastSlave and returns a slow slave when only slow
slaves are available and only_fast is False."""
slave = _nextFastSlave(self.builder, self.slow_slaves, only_fast=False)
self.assert_(slave.slave.slavename.startswith("slow"))
def test_nextFastSlave_allslow(self):
"""Test that _nextFastSlave works if the builder is configured with
just slow slaves. This handles the case for platforms that don't have a
fast/slow distinction."""
self.builder.slaves = self.slow_slaves
slave = _nextFastSlave(self.builder, self.slow_slaves, only_fast=True)
self.assert_(slave.slavename.startswith('slow'))
def test_nextSlowSlave(self):
"""Test that _nextSlowSlave returns a slow slave if one is available."""
slave = _nextSlowSlave(self.builder, self.slaves)
self.assert_(slave.slave.slavename.startswith("slow"))
def test_nextSlowSlave_OnlyFastAvail(self):
"""Test that _nextSlowSlave returns a fast slave if no slow slaves are
available."""
slave = _nextSlowSlave(self.builder, self.fast_slaves)
self.assert_(slave.slave.slavename.startswith("fast"))
def test_nextSlowIdleSlave_avail(self):
"""Test that _nextSlowIdleSlave returns a slow slave if enough slow
slaves are available."""
func = _nextSlowIdleSlave(1)
slave = func(self.builder, self.slaves)
self.assert_(slave.slave.slavename.startswith("slow"))
def test_nextSlowIdleSlave_unavail(self):
"""Test that _nextSlowIdleSlave returns None if not enough slow
slaves are available."""
func = _nextSlowIdleSlave(5)
slave = func(self.builder, self.slaves)
self.assert_(slave is None)