1 # -*- coding: utf-8 -*-
2 # Copyright 2013 Google Inc. All Rights Reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """Integration tests for perfdiag command."""
17 from __future__
import absolute_import
22 import gslib
.tests
.testcase
as testcase
23 from gslib
.tests
.util
import ObjectToURI
as suri
24 from gslib
.tests
.util
import unittest
25 from gslib
.util
import IS_WINDOWS
28 class TestPerfDiag(testcase
.GsUtilIntegrationTestCase
):
29 """Integration tests for perfdiag command."""
31 # We want to test that perfdiag works both when connecting to the standard gs
32 # endpoint, and when connecting to a specific IP or host while setting the
33 # host header. For the 2nd case we resolve storage.googleapis.com to a
34 # specific IP and connect to that explicitly.
35 _gs_ip
= socket
.gethostbyname('storage.googleapis.com')
36 _custom_endpoint_flags
= [
37 '-o', 'Credentials:gs_host=' + _gs_ip
,
38 '-o', 'Credentials:gs_host_header=storage.googleapis.com',
39 # TODO: gsutil-beta: Add host header support for JSON
40 '-o', 'Boto:https_validate_certificates=False']
42 def _should_run_with_custom_endpoints(self
):
43 # Host headers are only supported for XML, and not when
44 # using environment variables for proxies.
45 return self
.test_api
== 'XML' and not (os
.environ
.get('http_proxy') or
46 os
.environ
.get('https_proxy') or
47 os
.environ
.get('HTTPS_PROXY'))
49 def test_latency(self
):
50 bucket_uri
= self
.CreateBucket()
51 cmd
= ['perfdiag', '-n', '1', '-t', 'lat', suri(bucket_uri
)]
53 if self
._should
_run
_with
_custom
_endpoints
():
54 self
.RunGsUtil(self
._custom
_endpoint
_flags
+ cmd
)
55 self
.AssertNObjectsInBucket(bucket_uri
, 0, versioned
=True)
57 def _run_basic_wthru_or_rthru(self
, test_name
, num_processes
, num_threads
):
58 bucket_uri
= self
.CreateBucket()
59 cmd
= ['perfdiag', '-n', str(num_processes
* num_threads
),
60 '-s', '1024', '-c', str(num_processes
),
61 '-k', str(num_threads
), '-t', test_name
, suri(bucket_uri
)]
63 if self
._should
_run
_with
_custom
_endpoints
():
64 self
.RunGsUtil(self
._custom
_endpoint
_flags
+ cmd
)
65 self
.AssertNObjectsInBucket(bucket_uri
, 0, versioned
=True)
67 def test_write_throughput_single_process_single_thread(self
):
68 self
._run
_basic
_wthru
_or
_rthru
('wthru', 1, 1)
70 def test_write_throughput_single_process_multi_thread(self
):
71 self
._run
_basic
_wthru
_or
_rthru
('wthru', 1, 2)
73 @unittest.skipIf(IS_WINDOWS
, 'Multiprocessing is not supported on Windows')
74 def test_write_throughput_multi_process_single_thread(self
):
75 self
._run
_basic
_wthru
_or
_rthru
('wthru', 2, 1)
77 @unittest.skipIf(IS_WINDOWS
, 'Multiprocessing is not supported on Windows')
78 def test_write_throughput_multi_process_multi_thread(self
):
79 self
._run
_basic
_wthru
_or
_rthru
('wthru', 2, 2)
81 def test_read_throughput_single_process_single_thread(self
):
82 self
._run
_basic
_wthru
_or
_rthru
('rthru', 1, 1)
84 def test_read_throughput_single_process_multi_thread(self
):
85 self
._run
_basic
_wthru
_or
_rthru
('rthru', 1, 2)
87 @unittest.skipIf(IS_WINDOWS
, 'Multiprocessing is not supported on Windows')
88 def test_read_throughput_multi_process_single_thread(self
):
89 self
._run
_basic
_wthru
_or
_rthru
('rthru', 2, 1)
91 @unittest.skipIf(IS_WINDOWS
, 'Multiprocessing is not supported on Windows')
92 def test_read_throughput_multi_process_multi_thread(self
):
93 self
._run
_basic
_wthru
_or
_rthru
('rthru', 2, 2)
95 def test_input_output(self
):
96 outpath
= self
.CreateTempFile()
97 bucket_uri
= self
.CreateBucket()
98 self
.RunGsUtil(['perfdiag', '-o', outpath
, '-n', '1', '-t', 'lat',
100 self
.RunGsUtil(['perfdiag', '-i', outpath
])
102 def test_invalid_size(self
):
103 stderr
= self
.RunGsUtil(
104 ['perfdiag', '-n', '1', '-s', 'foo', '-t', 'wthru', 'gs://foobar'],
105 expected_status
=1, return_stderr
=True)
106 self
.assertIn('Invalid -s', stderr
)
108 def test_toobig_size(self
):
109 stderr
= self
.RunGsUtil(
110 ['perfdiag', '-n', '1', '-s', '3pb', '-t', 'wthru', 'gs://foobar'],
111 expected_status
=1, return_stderr
=True)
112 self
.assertIn('Maximum throughput file size', stderr
)
114 def test_listing(self
):
115 bucket_uri
= self
.CreateBucket()
116 stdout
= self
.RunGsUtil(
117 ['perfdiag', '-n', '1', '-t', 'list', suri(bucket_uri
)],
119 self
.assertIn('Number of listing calls made:', stdout
)
120 self
.AssertNObjectsInBucket(bucket_uri
, 0, versioned
=True)