~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/test_mgmt/execution_management.py

  • Committer: Lee Bieber
  • Date: 2011-01-26 23:24:31 UTC
  • mfrom: (2119.2.1 drizzle)
  • Revision ID: kalebral@gmail.com-20110126232431-rg5gwpmjlo3ya40f
Merge Patrick - Introduces new test runn dbqp.py which can be run side by side with existing test runner for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
4
#
 
5
# Copyright (C) 2010 Patrick Crews
 
6
#
 
7
"""execution_management.py
 
8
   code for dealing with test execution.
 
9
   The actual nuts and bolts of executing a test lies with the 
 
10
   mode-specific test-executor
 
11
 
 
12
   The code here is for managing the executors and such.
 
13
 
 
14
"""
 
15
 
 
16
# imports
 
17
import thread
 
18
import time
 
19
 
 
20
class executionManager:
 
21
    """ Manages the mode-specific test-executors
 
22
        and serves as an intermediary between the executors
 
23
        and the other management code (system, server, test)
 
24
 
 
25
    """
 
26
 
 
27
    def __init__(self, server_manager, system_manager, test_manager
 
28
                 , executor_type, variables):
 
29
 
 
30
        self.server_manager = server_manager
 
31
        self.system_manager = system_manager
 
32
        self.logging = system_manager.logging
 
33
        self.test_manager = test_manager
 
34
        if variables['verbose']:
 
35
            self.logging.info("Initializing test execution manager...")
 
36
        self.skip_keys = [ 'server_manager'
 
37
                         , 'system_manager'
 
38
                         , 'test_manager'
 
39
                         , 'executors'
 
40
                         , 'executor_start_count'
 
41
                         , 'executor_current_count'
 
42
                         ]
 
43
        
 
44
        self.debug = variables['debug']
 
45
        self.verbose = variables['verbose']
 
46
        self.force = variables['force']
 
47
        self.record_flag = variables['record']
 
48
        self.executors = {}
 
49
        self.executor_name_base = 'testbot'
 
50
        self.executor_start_count = 0
 
51
        self.executor_current_count = 0
 
52
        # We will eventually allow this to be set
 
53
        # by the user, but we are hard-coded at 1
 
54
        # for the moment (will = --parallel)
 
55
        self.executor_count = 1 
 
56
        self.executor_type = executor_type
 
57
 
 
58
        if self.debug:
 
59
            self.logging.debug_class(self)
 
60
 
 
61
 
 
62
    def execute_tests(self):
 
63
        """ Execute the testCases stored in the testManager
 
64
            via spawning executor_count of the mode-specific
 
65
            executor_types.
 
66
 
 
67
            Currently only supporting single executor, but trying
 
68
            to plan ahead
 
69
 
 
70
        """
 
71
        
 
72
        # create our testExecutors to execute the tests
 
73
        self.create_test_executors()
 
74
 
 
75
        # fire up the testExecutors and let them rip it up
 
76
        for executor_name, executor in self.executors.items():
 
77
            if self.verbose:
 
78
                self.logging.verbose("Starting executor: %s" %(executor_name))
 
79
                # thread.start_new(executor.execute,()) # sigh...one day...damned drizzletest!
 
80
            executor.execute()
 
81
        time.sleep(3)
 
82
        while self.has_running_executors():
 
83
            pass
 
84
        self.test_manager.statistical_report()
 
85
        self.logging.info("Test execution complete")
 
86
 
 
87
    def has_running_executors(self):
 
88
        """ We see if our executors are still running """
 
89
        for executor in self.executors.values():
 
90
            if executor.status == 1:
 
91
                return 1
 
92
        return 0
 
93
 
 
94
    def create_test_executors(self):
 
95
        """ create however many test executors of executor_type
 
96
            that we need (only supporting 1 for now)
 
97
 
 
98
        """
 
99
 
 
100
        self.logging.info("Creating %d %s(s)" %(self.executor_count
 
101
                                          , self.executor_name_base))
 
102
        for i in range(self.executor_start_count,self.executor_count,1):
 
103
            executor_name = "%s%d" %(self.executor_name_base,i)
 
104
            new_executor = self.create_test_executor(executor_name)
 
105
           
 
106
 
 
107
    def create_test_executor(self, executor_name):
 
108
        """ Create a single testExecutor """
 
109
        
 
110
        if self.verbose:
 
111
                self.logging.verbose("Creating %s" %(executor_name))
 
112
        new_executor = self.executor_type( self, executor_name
 
113
                                         , self.verbose, self.debug)
 
114
        self.log_executor(executor_name, new_executor)
 
115
 
 
116
    def log_executor(self, executor_name, new_executor):
 
117
        """ Bookkeeping function to track created executors """
 
118
        self.executors[executor_name] = new_executor
 
119
        self.executor_current_count += 1
 
120
 
 
121