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

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

Issue 870103005: Adding a server side, non-blocking subprocess mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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
15 import host_controller
16
17
18 class ExampleController(host_controller.HostController):
19 """An example controller using the remote subprocess functions."""
20
21 def __init__(self):
22 super(ExampleController, self).__init__()
23 self.client = None
24
25 def SetUp(self):
26 """Creates the client machine and waits until it connects."""
27 self.client = self.NewClient(
28 isolate_file='client.isolate',
29 config_vars={'multi_machine': '1'},
30 dimensions={'os': 'legion-linux'},
31 idle_timeout_secs=90, connection_timeout_secs=90,
32 verbosity=logging.DEBUG)
33 self.client.Create()
34 self.client.WaitForConnection()
35
36 def Task(self):
37 """Main method to run the task code."""
38 self.TestLs()
39 self.TestTerminate()
40 self.TestMultipleProcesses()
41
42 def TestMultipleProcesses(self):
43 start = time.time()
44 sleep20 = self.client.rpc.subprocess.Popen(['sleep', '20'])
45 sleep10 = self.client.rpc.subprocess.Popen(['sleep', '10'])
46 self.client.rpc.subprocess.Wait(sleep10)
47 elapsed = time.time() - start
48 assert elapsed >= 10 and elapsed < 11
49 self.client.rpc.subprocess.Wait(sleep20)
50 elapsed = time.time() - start
51 assert elapsed >= 20
52
53 def TestTerminate(self):
54 start = time.time()
55 proc = self.client.rpc.subprocess.Popen(['sleep', '20'])
56 self.client.rpc.subprocess.Terminate(proc)
57 self.client.rpc.subprocess.Wait(proc)
58 assert time.time() - start < 20
59
60 def TestLs(self):
61 proc = self.client.rpc.subprocess.Popen(['ls'])
62 self.client.rpc.subprocess.Wait(proc)
63 assert self.client.rpc.subprocess.GetReturncode(proc) == 0
64 assert 'client.isolate' in self.client.rpc.subprocess.GetStdout(proc)
65
66
67 if __name__ == '__main__':
68 ExampleController().RunController()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698