OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """A simple event server test case. |
| 7 |
| 8 This test will go through all of the possible event states and ensures their |
| 9 return codes are what are expected. |
| 10 """ |
| 11 |
| 12 import argparse |
| 13 import logging |
| 14 import os |
| 15 import sys |
| 16 import time |
| 17 |
| 18 # Map the testing directory so we can import legion.legion_test_case. |
| 19 TESTING_DIR = os.path.join( |
| 20 os.path.dirname(os.path.abspath(__file__)), |
| 21 '..', '..', '..', '..', 'testing') |
| 22 sys.path.append(TESTING_DIR) |
| 23 |
| 24 from legion import legion_test_case |
| 25 from legion.lib import common_lib |
| 26 |
| 27 |
| 28 class EventTestController(legion_test_case.TestCase): |
| 29 """A simple example controller for a test.""" |
| 30 |
| 31 @classmethod |
| 32 def CreateTestTask(cls): |
| 33 """Create a new task.""" |
| 34 parser = argparse.ArgumentParser() |
| 35 parser.add_argument('--task-hash') |
| 36 parser.add_argument('--os', default='Ubuntu-14.04') |
| 37 args, _ = parser.parse_known_args() |
| 38 |
| 39 task = cls.CreateTask( |
| 40 isolated_hash=args.task_hash, |
| 41 dimensions={'os': args.os}, |
| 42 idle_timeout_secs=90, |
| 43 connection_timeout_secs=90, |
| 44 verbosity=logging.DEBUG) |
| 45 task.Create() |
| 46 return task |
| 47 |
| 48 @classmethod |
| 49 def setUpClass(cls): |
| 50 """Creates the task machines and waits until they connect.""" |
| 51 cls.task = cls.CreateTestTask() |
| 52 cls.task.WaitForConnection() |
| 53 |
| 54 def testEventTest(self): |
| 55 cmd = [ |
| 56 'python', |
| 57 'task.py', |
| 58 '--address', str(common_lib.MY_IP), |
| 59 '--port', str(self.event_server.port) |
| 60 ] |
| 61 process = self.task.Process(cmd) |
| 62 process.Wait() |
| 63 retcode = process.GetReturncode() |
| 64 if retcode != 0: |
| 65 logging.info('STDOUT:\n%s', process.ReadStdout()) |
| 66 logging.info('STDERR:\n%s', process.ReadStderr()) |
| 67 self.assertEqual(retcode, 0) |
| 68 # Add a success logging statement to make the logs a little easier to read. |
| 69 logging.info('Success') |
| 70 |
| 71 |
| 72 if __name__ == '__main__': |
| 73 legion_test_case.main() |
OLD | NEW |