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
3 # found in the LICENSE file.
9 TESTING_DIR
= os
.path
.join(
10 os
.path
.dirname(os
.path
.abspath(__file__
)), '..', '..', '..')
11 sys
.path
.append(TESTING_DIR
)
13 from legion
import legion_test_case
16 class HttpTest(legion_test_case
.TestCase
):
17 """Example HTTP test case."""
21 """Get command line args."""
22 parser
= argparse
.ArgumentParser()
23 parser
.add_argument('--http-server')
24 parser
.add_argument('--http-client')
25 parser
.add_argument('--os', default
='Ubuntu-14.04')
26 args
, _
= parser
.parse_known_args()
30 def CreateTask(cls
, name
, task_hash
, os_type
):
31 """Create a new task."""
32 #pylint: disable=unexpected-keyword-arg,no-value-for-parameter
33 task
= super(HttpTest
, cls
).CreateTask(
35 isolated_hash
=task_hash
,
36 dimensions
={'os': os_type
})
42 """Creates the task machines and waits until they connect."""
44 cls
.http_server
= cls
.CreateTask(
45 'http_server', args
.http_server
, args
.os
)
46 cls
.http_client
= cls
.CreateTask(
47 'http_client', args
.http_client
, args
.os
)
48 cls
.http_server
.WaitForConnection()
49 cls
.http_client
.WaitForConnection()
51 def testHttpWorks(self
):
56 server_ip
= self
.http_server
.rpc
.GetIpAddress()
57 server_proc
= self
.http_server
.Process(
58 ['python', 'http_server.py', '--port', server_port
])
59 client_proc
= self
.http_client
.Process(
60 ['python', 'http_client.py', '--server', server_ip
,
61 '--port', server_port
])
63 self
.assertEqual(client_proc
.GetReturncode(), 0)
73 if __name__
== '__main__':
74 legion_test_case
.main()