1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import os
21 import qm.common
22 from qm.test.base import *
23 from qm.test.context import *
24 from qm.test.execution_engine import *
25 import qm.xmlutil
26 import Queue
27 from result import *
28 import sys
29 from threading import *
30
31
32
33
34
36 """A 'ExecutionThread' executes tests in a separate thread.
37
38 A 'ExecutionThread' is an 'ExecutionEngine' that runs tests in a
39 separate thread.
40
41 This class schedules the tests, plus the setup and cleanup of any
42 resources they require, across one or more targets.
43
44 The shedule is determined dynamically as the tests are executed
45 based on which targets are idle and which are not. Therefore, the
46 testing load should be reasonably well balanced, even across a
47 heterogeneous network of testing machines."""
48
49 - def __init__(self,
50 database,
51 test_ids,
52 context,
53 targets,
54 result_streams = None,
55 expectations = None):
56 """Set up a test run.
57
58 'database' -- The 'Database' containing the tests that will be
59 run.
60
61 'test_ids' -- A sequence of IDs of tests to run. Where
62 possible, the tests are started in the order specified.
63
64 'context' -- The context object to use when running tests.
65
66 'targets' -- A sequence of 'Target' objects, representing
67 targets on which tests may be run.
68
69 'result_streams' -- A sequence of 'ResultStream' objects. Each
70 stream will be provided with results as they are available.
71 This thread will not perform any locking of these streams as
72 they are written to; each stream must provide its own
73 synchronization if it will be accessed before 'run' returns.
74
75 'expectations' -- If not 'None', a dictionary mapping test IDs
76 to expected outcomes."""
77
78 Thread.__init__(self, None, None, None)
79 ExecutionEngine.__init__(self, database, test_ids, context,
80 targets, result_streams, expectations)
81
82
83
84
85
86
87 self.setDaemon(1)
88
89
90 self.__lock = Lock()
91
92
94 """Run the tests.
95
96 This method runs the tests specified in the __init__
97 function."""
98 self.Run()
99
100
102 """Request termination.
103
104 Request that the execution thread be terminated. This may
105 take some time; tests that are already running will continue
106 to run, for example."""
107
108 self.__lock.acquire()
109 ExecutionEngine.RequestTermination(self)
110 self.__lock.release()
111
112
114 """Returns true if termination has been requested.
115
116 return -- True if Terminate has been called."""
117
118 self.__lock.acquire()
119 terminated = ExecutionEngine._IsTerminationRequested(self)
120 self.__lock.release()
121 return terminated
122
123
124
125
126
127
128
129
130