Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Don't use an asyncio.Lock for ADB commands (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed May 10, 2020
1 parent 0fd9859 commit 7de0ff3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
34 changes: 17 additions & 17 deletions aio_androidtv/adb_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ async def pull(self, local_path, device_path):
_LOGGER.debug("ADB command not sent to %s:%d because adb-shell connection is not established: pull(%s, %s)", self.host, self.port, local_path, device_path)
return

async with _acquire(self._adb_lock):
_LOGGER.debug("Sending command to %s:%d via adb-shell: pull(%s, %s)", self.host, self.port, local_path, device_path)
await self._adb.pull(device_path, local_path)
return
# async with _acquire(self._adb_lock):
_LOGGER.debug("Sending command to %s:%d via adb-shell: pull(%s, %s)", self.host, self.port, local_path, device_path)
await self._adb.pull(device_path, local_path)
return

async def push(self, local_path, device_path):
"""Push a file to the device using the Python ADB implementation.
Expand All @@ -209,10 +209,10 @@ async def push(self, local_path, device_path):
_LOGGER.debug("ADB command not sent to %s:%d because adb-shell connection is not established: push(%s, %s)", self.host, self.port, local_path, device_path)
return

async with _acquire(self._adb_lock):
_LOGGER.debug("Sending command to %s:%d via adb-shell: push(%s, %s)", self.host, self.port, local_path, device_path)
await self._adb.push(local_path, device_path)
return
# async with _acquire(self._adb_lock):
_LOGGER.debug("Sending command to %s:%d via adb-shell: push(%s, %s)", self.host, self.port, local_path, device_path)
await self._adb.push(local_path, device_path)
return

async def screencap(self):
"""Take a screenshot using the Python ADB implementation.
Expand All @@ -227,12 +227,12 @@ async def screencap(self):
_LOGGER.debug("ADB screencap not taken from %s:%d because adb-shell connection is not established", self.host, self.port)
return None

async with _acquire(self._adb_lock):
_LOGGER.debug("Taking screencap from %s:%d via adb-shell", self.host, self.port)
result = await self._adb.shell("screencap -p", decode=False)
if result[5:6] == b"\r":
return result.replace(b"\r\n", b"\n")
return result
# async with _acquire(self._adb_lock):
_LOGGER.debug("Taking screencap from %s:%d via adb-shell", self.host, self.port)
result = await self._adb.shell("screencap -p", decode=False)
if result[5:6] == b"\r":
return result.replace(b"\r\n", b"\n")
return result

async def shell(self, cmd):
"""Send an ADB command using the Python ADB implementation.
Expand All @@ -252,6 +252,6 @@ async def shell(self, cmd):
_LOGGER.debug("ADB command not sent to %s:%d because adb-shell connection is not established: %s", self.host, self.port, cmd)
return None

async with _acquire(self._adb_lock):
_LOGGER.debug("Sending command to %s:%d via adb-shell: %s", self.host, self.port, cmd)
return await self._adb.shell(cmd)
# async with _acquire(self._adb_lock):
_LOGGER.debug("Sending command to %s:%d via adb-shell: %s", self.host, self.port, cmd)
return await self._adb.shell(cmd)
16 changes: 8 additions & 8 deletions tests/test_adb_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def test_connect_fail_lock(self):
self.assertFalse(self.adb._available)

@awaiter
async def test_adb_shell_fail(self):
async def _test_adb_shell_fail(self):
"""Test when an ADB shell command is not sent because the device is unavailable.
"""
Expand All @@ -195,7 +195,7 @@ async def test_adb_shell_success(self):
self.assertEqual(await self.adb.shell("TEST"), "TEST")

@awaiter
async def test_adb_shell_fail_lock_released(self):
async def _test_adb_shell_fail_lock_released(self):
"""Test that the ADB lock gets released when an exception is raised.
"""
Expand All @@ -209,7 +209,7 @@ async def test_adb_shell_fail_lock_released(self):
assert release.called

@awaiter
async def test_adb_shell_lock_not_acquired_not_released(self):
async def _test_adb_shell_lock_not_acquired_not_released(self):
"""Test that the lock does not get released if it is not acquired.
"""
Expand All @@ -235,14 +235,14 @@ async def test_adb_push_fail(self):
await self.adb.push("TEST_LOCAL_PATCH", "TEST_DEVICE_PATH")
patch_push.assert_not_called()

with patchers.patch_connect(True)[self.PATCH_KEY]:
'''with patchers.patch_connect(True)[self.PATCH_KEY]:
with patchers.PATCH_PUSH[self.PATCH_KEY] as patch_push:
self.assertTrue(await self.adb.connect())
with patch.object(self.adb, '_adb_lock', AsyncLockedLock()):
with self.assertRaises(LockNotAcquiredException):
await self.adb.push("TEST_LOCAL_PATH", "TEST_DEVICE_PATH")
patch_push.assert_not_called()
patch_push.assert_not_called()'''

@awaiter
async def test_adb_push_success(self):
Expand All @@ -266,13 +266,13 @@ async def test_adb_pull_fail(self):
await self.adb.pull("TEST_LOCAL_PATCH", "TEST_DEVICE_PATH")
patch_pull.assert_not_called()

with patchers.patch_connect(True)[self.PATCH_KEY]:
'''with patchers.patch_connect(True)[self.PATCH_KEY]:
with patchers.PATCH_PULL[self.PATCH_KEY] as patch_pull:
self.assertTrue(await self.adb.connect())
with patch.object(self.adb, '_adb_lock', AsyncLockedLock()):
with self.assertRaises(LockNotAcquiredException):
await self.adb.pull("TEST_LOCAL_PATH", "TEST_DEVICE_PATH")
patch_pull.assert_not_called()
patch_pull.assert_not_called()'''

@awaiter
async def test_adb_pull_success(self):
Expand All @@ -294,7 +294,7 @@ async def test_adb_screencap_fail_unavailable(self):
self.assertIsNone(await self.adb.screencap())

@awaiter
async def test_adb_screencap_lock_not_acquired(self):
async def _test_adb_screencap_lock_not_acquired(self):
"""Test when an ADB screencap command fails because the ADB lock could not be acquired.
"""
Expand Down

0 comments on commit 7de0ff3

Please sign in to comment.