| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A host test module demonstrating interacting with remote subprocesses.""" | 6 """A host test module demonstrating interacting with remote subprocesses.""" |
| 7 | 7 |
| 8 # Map the legion directory so we can import the host controller. | 8 # Map the legion directory so we can import the host controller. |
| 9 import sys | 9 import sys |
| 10 sys.path.append('../../') | 10 sys.path.append('../../') |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 self.task = None | 25 self.task = None |
| 26 | 26 |
| 27 def SetUp(self): | 27 def SetUp(self): |
| 28 """Creates the task machine and waits until it connects.""" | 28 """Creates the task machine and waits until it connects.""" |
| 29 parser = argparse.ArgumentParser() | 29 parser = argparse.ArgumentParser() |
| 30 parser.add_argument('--task-hash') | 30 parser.add_argument('--task-hash') |
| 31 args, _ = parser.parse_known_args() | 31 args, _ = parser.parse_known_args() |
| 32 | 32 |
| 33 self.task = self.CreateNewTask( | 33 self.task = self.CreateNewTask( |
| 34 isolated_hash=args.task_hash, | 34 isolated_hash=args.task_hash, |
| 35 dimensions={'os': 'Ubuntu-14.04', 'pool': 'Legion'}, | 35 dimensions={'os': 'Ubuntu-14.04', 'pool': 'Chromoting'}, |
| 36 idle_timeout_secs=90, connection_timeout_secs=90, | 36 idle_timeout_secs=90, connection_timeout_secs=90, |
| 37 verbosity=logging.DEBUG) | 37 verbosity=logging.DEBUG) |
| 38 self.task.Create() | 38 self.task.Create() |
| 39 self.task.WaitForConnection() | 39 self.task.WaitForConnection() |
| 40 | 40 |
| 41 def RunTest(self): | 41 def RunTest(self): |
| 42 """Main method to run the test code.""" | 42 """Main method to run the test code.""" |
| 43 self.TestLs() | 43 self.TestLs() |
| 44 self.TestTerminate() | 44 self.TestTerminate() |
| 45 self.TestMultipleProcesses() | 45 self.TestMultipleProcesses() |
| 46 | 46 |
| 47 def TestMultipleProcesses(self): | 47 def TestMultipleProcesses(self): |
| 48 start = time.time() | 48 start = time.time() |
| 49 | 49 |
| 50 sleep20 = self.task.rpc.subprocess.Popen(['sleep', '20']) | 50 sleep20 = self.task.rpc.subprocess.Process(['sleep', '20']) |
| 51 sleep10 = self.task.rpc.subprocess.Popen(['sleep', '10']) | 51 self.task.rpc.subprocess.Start(sleep20) |
| 52 sleep10 = self.task.rpc.subprocess.Process(['sleep', '10']) |
| 53 self.task.rpc.subprocess.Start(sleep10) |
| 52 | 54 |
| 53 self.task.rpc.subprocess.Wait(sleep10) | 55 self.task.rpc.subprocess.Wait(sleep10) |
| 54 elapsed = time.time() - start | 56 elapsed = time.time() - start |
| 55 assert elapsed >= 10 and elapsed < 11 | 57 assert elapsed >= 10 and elapsed < 11 |
| 56 | 58 |
| 57 self.task.rpc.subprocess.Wait(sleep20) | 59 self.task.rpc.subprocess.Wait(sleep20) |
| 58 elapsed = time.time() - start | 60 elapsed = time.time() - start |
| 59 assert elapsed >= 20 | 61 assert elapsed >= 20 |
| 60 | 62 |
| 61 self.task.rpc.subprocess.Delete(sleep20) | 63 self.task.rpc.subprocess.Delete(sleep20) |
| 62 self.task.rpc.subprocess.Delete(sleep10) | 64 self.task.rpc.subprocess.Delete(sleep10) |
| 63 | 65 |
| 64 def TestTerminate(self): | 66 def TestTerminate(self): |
| 65 start = time.time() | 67 start = time.time() |
| 66 proc = self.task.rpc.subprocess.Popen(['sleep', '20']) | 68 proc = self.task.rpc.subprocess.Process(['sleep', '20']) |
| 67 self.task.rpc.subprocess.Terminate(proc) # Implicitly deleted | 69 self.task.rpc.subprocess.Start(proc) |
| 70 self.task.rpc.subprocess.Terminate(proc) |
| 68 try: | 71 try: |
| 69 self.task.rpc.subprocess.Wait(proc) | 72 self.task.rpc.subprocess.Wait(proc) |
| 70 except xmlrpclib.Fault: | 73 except xmlrpclib.Fault: |
| 71 pass | 74 pass |
| 75 finally: |
| 76 self.task.rpc.subprocess.Delete(proc) |
| 72 assert time.time() - start < 20 | 77 assert time.time() - start < 20 |
| 73 | 78 |
| 74 def TestLs(self): | 79 def TestLs(self): |
| 75 proc = self.task.rpc.subprocess.Popen(['ls']) | 80 proc = self.task.rpc.subprocess.Process(['ls']) |
| 81 self.task.rpc.subprocess.Start(proc) |
| 76 self.task.rpc.subprocess.Wait(proc) | 82 self.task.rpc.subprocess.Wait(proc) |
| 77 assert self.task.rpc.subprocess.GetReturncode(proc) == 0 | 83 assert self.task.rpc.subprocess.GetReturncode(proc) == 0 |
| 78 assert 'task.isolate' in self.task.rpc.subprocess.ReadStdout(proc) | 84 assert 'task.isolate' in self.task.rpc.subprocess.ReadStdout(proc) |
| 79 self.task.rpc.subprocess.Delete(proc) | 85 self.task.rpc.subprocess.Delete(proc) |
| 80 | 86 |
| 81 | 87 |
| 82 if __name__ == '__main__': | 88 if __name__ == '__main__': |
| 83 ExampleTestController().RunController() | 89 ExampleTestController().RunController() |
| OLD | NEW |