Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: testing/legion/examples/subprocess/subprocess_test.py

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """A host test module demonstrating interacting with remote subprocesses."""
7
8 # Map the legion directory so we can import the host controller.
9 import sys
10 sys.path.append('../../')
11
12 import logging
13 import time
14 import xmlrpclib
15
16 import host_controller
17
18
19 class ExampleController(host_controller.HostController):
20 """An example controller using the remote subprocess functions."""
21
22 def __init__(self):
23 super(ExampleController, self).__init__()
24 self.client = None
25
26 def SetUp(self):
27 """Creates the client machine and waits until it connects."""
28 self.client = self.NewClient(
29 isolate_file='client.isolate',
30 config_vars={'multi_machine': '1'},
31 dimensions={'os': 'legion-linux'},
32 idle_timeout_secs=90, connection_timeout_secs=90,
33 verbosity=logging.DEBUG)
34 self.client.Create()
35 self.client.WaitForConnection()
36
37 def Task(self):
38 """Main method to run the task code."""
39 self.TestLs()
40 self.TestTerminate()
41 self.TestMultipleProcesses()
42
43 def TestMultipleProcesses(self):
44 start = time.time()
45
46 sleep20 = self.client.rpc.subprocess.Popen(['sleep', '20'])
47 sleep10 = self.client.rpc.subprocess.Popen(['sleep', '10'])
48
49 self.client.rpc.subprocess.Wait(sleep10)
50 elapsed = time.time() - start
51 assert elapsed >= 10 and elapsed < 11
52
53 self.client.rpc.subprocess.Wait(sleep20)
54 elapsed = time.time() - start
55 assert elapsed >= 20
56
57 self.client.rpc.subprocess.Delete(sleep20)
58 self.client.rpc.subprocess.Delete(sleep10)
59
60 def TestTerminate(self):
61 start = time.time()
62 proc = self.client.rpc.subprocess.Popen(['sleep', '20'])
63 self.client.rpc.subprocess.Terminate(proc) # Implicitly deleted
64 try:
65 self.client.rpc.subprocess.Wait(proc)
66 except xmlrpclib.Fault:
67 pass
68 assert time.time() - start < 20
69
70 def TestLs(self):
71 proc = self.client.rpc.subprocess.Popen(['ls'])
72 self.client.rpc.subprocess.Wait(proc)
73 assert self.client.rpc.subprocess.GetReturncode(proc) == 0
74 assert 'client.isolate' in self.client.rpc.subprocess.ReadStdout(proc)
75 self.client.rpc.subprocess.Delete(proc)
76
77
78 if __name__ == '__main__':
79 ExampleController().RunController()
OLDNEW
« no previous file with comments | « testing/legion/examples/subprocess/subprocess_test.isolate ('k') | testing/scripts/host_info.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698