Skip to content

Commit 800be08

Browse files
kenjitoyamacopybara-github
authored andcommitted
Fix Order-dependent test.
This test could sometimes fail due to OS environment variables and config not set up properly. This change makes the config value explicit (`True`) and removes the unnecessary expected calls. PiperOrigin-RevId: 834274607
1 parent 7ad994f commit 800be08

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

android_env/components/adb_controller_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Tests for android_env.components.adb_controller."""
17-
1816
import os
1917
import subprocess
2018
import time
@@ -110,6 +108,8 @@ def test_init_server_with_adb_server_port_from_os_env(
110108
@mock.patch.object(subprocess, 'check_output', autospec=True)
111109
@mock.patch.object(time, 'sleep', autospec=True)
112110
def test_restart_server(self, mock_sleep, mock_check_output):
111+
"""When an adb command fails, we expect the server to be restarted."""
112+
113113
# Arrange.
114114
mock_check_output.side_effect = [
115115
subprocess.CalledProcessError(returncode=1, cmd='blah'),
@@ -118,7 +118,7 @@ def test_restart_server(self, mock_sleep, mock_check_output):
118118
config_classes.AdbControllerConfig(
119119
adb_path='my_adb',
120120
device_name='awesome_device',
121-
adb_server_port=9999,
121+
use_adb_server_port_from_os_env=True,
122122
)
123123
)
124124

@@ -130,31 +130,31 @@ def test_restart_server(self, mock_sleep, mock_check_output):
130130
expected_env['HOME'] = '/some/path/'
131131
mock_check_output.assert_has_calls([
132132
mock.call(
133-
['my_adb', '-P', '9999', '-s', 'awesome_device', 'my_command'],
133+
['my_adb', '-s', 'awesome_device', 'my_command'],
134134
stderr=subprocess.STDOUT,
135135
timeout=_TIMEOUT,
136136
env=expected_env,
137137
),
138138
mock.call(
139-
['my_adb', '-P', '9999', 'kill-server'],
139+
['my_adb', 'kill-server'],
140140
stderr=subprocess.STDOUT,
141141
timeout=_TIMEOUT,
142142
env=expected_env,
143143
),
144144
mock.call(
145-
['my_adb', '-P', '9999', 'start-server'],
145+
['my_adb', 'start-server'],
146146
stderr=subprocess.STDOUT,
147147
timeout=_TIMEOUT,
148148
env=expected_env,
149149
),
150150
mock.call(
151-
['my_adb', '-P', '9999', 'devices'],
151+
['my_adb', 'devices'],
152152
stderr=subprocess.STDOUT,
153153
timeout=_TIMEOUT,
154154
env=expected_env,
155155
),
156156
mock.call(
157-
['my_adb', '-P', '9999', '-s', 'awesome_device', 'my_command'],
157+
['my_adb', '-s', 'awesome_device', 'my_command'],
158158
stderr=subprocess.STDOUT,
159159
timeout=_TIMEOUT,
160160
env=expected_env,

0 commit comments

Comments
 (0)