OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Adds unittest-esque functionality to Legion.""" | 5 """Adds unittest-esque functionality to Legion.""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import logging | 8 import logging |
9 import sys | 9 import sys |
10 import unittest | 10 import unittest |
11 | 11 |
12 # pylint: disable=relative-import | 12 # pylint: disable=relative-import |
13 # Import common_lib first so we can setup the environment | 13 # Import common_lib first so we can setup the environment |
14 from lib import common_lib | 14 from lib import common_lib |
15 common_lib.SetupEnvironment() | 15 common_lib.SetupEnvironment() |
16 | 16 |
| 17 from legion.lib import event_server |
17 from legion.lib import task_controller | 18 from legion.lib import task_controller |
18 from legion.lib import task_registration_server | 19 from legion.lib import task_registration_server |
19 | 20 |
20 BANNER_WIDTH = 80 | 21 BANNER_WIDTH = 80 |
21 | 22 |
22 | 23 |
23 class TestCase(unittest.TestCase): | 24 class TestCase(unittest.TestCase): |
24 """Test case class with added Legion support.""" | 25 """Test case class with added Legion support.""" |
25 | 26 |
26 _registration_server = None | 27 _registration_server = None |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 """Convenience method to create a new task.""" | 92 """Convenience method to create a new task.""" |
92 task = task_controller.TaskController( | 93 task = task_controller.TaskController( |
93 reg_server_port=cls._registration_server.port, *args, **kwargs) | 94 reg_server_port=cls._registration_server.port, *args, **kwargs) |
94 cls._registration_server.RegisterTaskCallback( | 95 cls._registration_server.RegisterTaskCallback( |
95 task.otp, task.OnConnect) | 96 task.otp, task.OnConnect) |
96 return task | 97 return task |
97 | 98 |
98 @classmethod | 99 @classmethod |
99 def _SetUpFramework(cls): | 100 def _SetUpFramework(cls): |
100 """Perform the framework-specific setup operations.""" | 101 """Perform the framework-specific setup operations.""" |
| 102 # Setup the registration server |
101 cls._registration_server = ( | 103 cls._registration_server = ( |
102 task_registration_server.TaskRegistrationServer()) | 104 task_registration_server.TaskRegistrationServer()) |
| 105 common_lib.OnShutdown += cls._registration_server.Shutdown |
103 cls._registration_server.Start() | 106 cls._registration_server.Start() |
104 | 107 |
| 108 # Setup the event server |
| 109 cls.event_server = event_server.ThreadedServer() |
| 110 common_lib.OnShutdown += cls.event_server.shutdown |
| 111 cls.event_server.start() |
| 112 |
105 @classmethod | 113 @classmethod |
106 def _TearDownFramework(cls): | 114 def _TearDownFramework(cls): |
107 """Perform the framework-specific teardown operations.""" | 115 """Perform the framework-specific teardown operations.""" |
108 common_lib.Shutdown() | 116 common_lib.Shutdown() |
109 | 117 |
110 @classmethod | 118 @classmethod |
111 def _HandleSetUpClass(cls): | 119 def _HandleSetUpClass(cls): |
112 """Performs common class-level setup operations. | 120 """Performs common class-level setup operations. |
113 | 121 |
114 This method performs test-wide setup such as starting the registration | 122 This method performs test-wide setup such as starting the registration |
(...skipping 19 matching lines...) Expand all Loading... |
134 cls._LogInfoBanner('tearDownClass', 'Performs class level tear down.') | 142 cls._LogInfoBanner('tearDownClass', 'Performs class level tear down.') |
135 try: | 143 try: |
136 if not setup_failed: | 144 if not setup_failed: |
137 cls._OriginalTearDownClassMethod() | 145 cls._OriginalTearDownClassMethod() |
138 finally: | 146 finally: |
139 cls._TearDownFramework() | 147 cls._TearDownFramework() |
140 | 148 |
141 | 149 |
142 def main(): | 150 def main(): |
143 unittest.main(verbosity=0, argv=sys.argv[:1]) | 151 unittest.main(verbosity=0, argv=sys.argv[:1]) |
OLD | NEW |