Package qm :: Package test :: Module execution_engine :: Class ExecutionEngine
[hide private]
[frames] | no frames]

Class ExecutionEngine

source code

A 'ExecutionEngine' executes tests.

A 'ExecutionEngine' object handles the execution of a collection of tests.

This class schedules the tests across one or more targets.

The shedule is determined dynamically as the tests are executed based on which targets are idle and which are not. Therefore, the testing load should be reasonably well balanced, even across a heterogeneous network of testing machines.

Nested Classes [hide private]
  __TestStatus
A '__TestStatus' indicates whether or not a test has been run.
Instance Methods [hide private]
 
__init__(self, database, test_ids, context, targets, result_streams=None, expectations=None)
Set up a test run.
source code
 
RequestTermination(self)
Request that the execution engine stop executing tests.
source code
 
_IsTerminationRequested(self)
Returns true if termination has been requested.
source code
 
Run(self)
Run the tests.
source code
 
AddInputHandler(self, fd, function)
Add an input handler for 'fd'.
source code
 
_RunTests(self) source code
 
__FeedTarget(self, target)
Run a test on 'target'
source code
 
__FindRunnableTest(self, target)
Return a test that is ready to run.
source code
 
__AddTestToStack(self, test_id)
Adds 'test_id' to the stack of current tests.
source code
 
__AddToTargetPatternQueue(self, descriptor)
A a test to the appropriate target pattern queue.
source code
 
__GetPendingPrerequisites(self, descriptor)
Return pending prerequisite tests for 'descriptor'.
source code
 
__AddResult(self, result)
Report the result of running a test or resource.
source code
 
__CheckForResponse(self, wait)
See if any of the targets have completed a task.
source code
 
__AddUntestedResult(self, test_name, cause, annotations={}, exc_info=None)
Add a 'Result' indicating that 'test_name' was not run.
source code
 
__GetTestDescriptor(self, test_id)
Return the 'TestDescriptor' for 'test_id'.
source code
 
_Trace(self, message)
Write a trace 'message'.
source code
 
_WriteInitialAnnotations(self) source code
Class Variables [hide private]
  __TARGET_IDLE = "IDLE"
  __TARGET_BUSY = "BUSY"
  __TARGET_STARVING = "STARVING"
Method Details [hide private]

__init__(self, database, test_ids, context, targets, result_streams=None, expectations=None)
(Constructor)

source code 

Set up a test run.

'database' -- The 'Database' containing the tests that will be run.

'test_ids' -- A sequence of IDs of tests to run. Where possible, the tests are started in the order specified.

'context' -- The context object to use when running tests.

'targets' -- A sequence of 'Target' objects, representing targets on which tests may be run.

'result_streams' -- A sequence of 'ResultStream' objects. Each stream will be provided with results as they are available.

'expectations' -- If not 'None', an ExpectationDatabase object.

RequestTermination(self)

source code 

Request that the execution engine stop executing tests.

Request that the execution thread be terminated. Termination may take some time; tests that are already running will continue to run, for example.

_IsTerminationRequested(self)

source code 

Returns true if termination has been requested.

returns -- True if no further tests should be executed. If the value is -1, the execution engine should simply terminate gracefully.

Run(self)

source code 

Run the tests.

This method runs the tests specified in the __init__ function.

returns -- True if any tests had unexpected outcomes.

AddInputHandler(self, fd, function)

source code 

Add an input handler for 'fd'.

'fd' -- A file descriptor, open for reading.

'function' -- A callable object taking a single parameter.

The execution engine will periodically monitor 'fd'. When input is available, it will call 'function' passing it 'fd'.

__FeedTarget(self, target)

source code 

Run a test on 'target'

'target' -- The 'Target' on which the test should be run.

returns -- True, iff a test could be found to run on 'target'. False otherwise.

__FindRunnableTest(self, target)

source code 

Return a test that is ready to run.

'target' -- The 'Target' on which the test will run.

returns -- the 'TestDescriptor' for the next available ready test, or 'None' if no test could be found that will run on 'target'.

If a test with unsatisfied prerequisites is encountered, the test will be pushed on the stack and the prerequisites processed recursively.

__AddTestToStack(self, test_id)

source code 

Adds 'test_id' to the stack of current tests.

returns -- True if the test was added to the stack; false if the test could not be loaded. In the latter case, an 'UNTESTED' result is recorded for the test.

__AddToTargetPatternQueue(self, descriptor)

source code 

A a test to the appropriate target pattern queue.

'descriptor' -- A 'TestDescriptor'.

Adds the test to the target pattern queue indicated in the descriptor.

__GetPendingPrerequisites(self, descriptor)

source code 

Return pending prerequisite tests for 'descriptor'.

'descriptor' -- A 'TestDescriptor'.

returns -- A list of prerequisite test ids that have to complete, or 'None' if one of the prerequisites had an unexpected outcome.

__AddResult(self, result)

source code 

Report the result of running a test or resource.

'result' -- A 'Result' object representing the result of running a test or resource.

__CheckForResponse(self, wait)

source code 

See if any of the targets have completed a task.

'wait' -- If false, this function returns immediately if there is no available response. If 'wait' is true, this function continues to wait until a response is available.

returns -- True iff a response was received.

__AddUntestedResult(self, test_name, cause, annotations={}, exc_info=None)

source code 

Add a 'Result' indicating that 'test_name' was not run.

'test_name' -- The label for the test that could not be run.

'cause' -- A string explaining why the test could not be run.

'annotations' -- A map from strings to strings giving additional annotations for the result.

'exc_info' -- If this test could not be tested due to a thrown exception, 'exc_info' is the result of 'sys.exc_info()' when the exception was caught. 'None' otherwise.

__GetTestDescriptor(self, test_id)

source code 

Return the 'TestDescriptor' for 'test_id'.

returns -- The 'TestDescriptor' for 'test_id', or 'None' if the descriptor could not be loaded.

If the database cannot load the descriptor, an 'UNTESTED' result is recorded for 'test_id'.

_Trace(self, message)

source code 

Write a trace 'message'.

'message' -- A string to be output as a trace message.