Skip to content

Commit fe200fb

Browse files
authored
Revert "Lock for API calls (#26)" (#36)
This reverts commit 5fca4ba.
1 parent 9ac6d16 commit fe200fb

File tree

4 files changed

+5
-49
lines changed

4 files changed

+5
-49
lines changed

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
"stf-client==0.1.0",
4545
"pydash",
4646
"easyprocess",
47-
"requests",
48-
"pid"
47+
"requests"
4948
],
5049
entry_points={
5150
'console_scripts': [

stf_appium_client/StfClient.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from stf_appium_client.Logger import Logger
1111
from stf_appium_client.exceptions import DeviceNotFound, NotConnectedError
12-
from stf_appium_client.tools import lock
1312
from stf_client.api_client import ApiClient, Configuration
1413
from stf_client.api.user_api import UserApi
1514
from stf_client.api.devices_api import DevicesApi
@@ -81,8 +80,7 @@ def allocate(self, device: dict, timeout_seconds: int = DEFAULT_ALLOCATION_TIMEO
8180
timeout = timeout_seconds * 1000
8281

8382
api_instance = UserApi(self._client)
84-
with lock():
85-
api_response = api_instance.add_user_device_v2(serial, timeout=timeout)
83+
api_response = api_instance.add_user_device_v2(serial, timeout=timeout)
8684
assert api_response.success, 'allocation fails'
8785
self.logger.info(f'{serial}: Allocated (timeout: {timeout_seconds})')
8886
device['owner'] = "me"
@@ -144,8 +142,7 @@ def release(self, device: dict) -> None:
144142
self.logger.debug(f'{serial}: releasing..')
145143

146144
api_instance = UserApi(self._client)
147-
with lock():
148-
api_response = api_instance.delete_user_device_by_serial(serial)
145+
api_response = api_instance.delete_user_device_by_serial(serial)
149146
assert api_response.success, 'release fails'
150147
device['owner'] = None
151148
self.logger.info(f'{serial}: released')

stf_appium_client/tools.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import socket
22
import json
33
import shutil
4-
import tempfile
5-
from contextlib import closing, contextmanager
6-
from pid import PidFile, PidFileError
4+
from contextlib import closing
75

86

97
def find_free_port() -> int:
@@ -55,17 +53,3 @@ def split(dest, subkey):
5553
dest[subkey] = value
5654
split(requirements, key)
5755
return requirements
58-
59-
@contextmanager
60-
def lock():
61-
"""
62-
Master lock
63-
"""
64-
try:
65-
lockfile = PidFile(pidname='stf.pid', piddir=tempfile.gettempdir(), register_term_signal_handler=False)
66-
lockfile.create()
67-
yield lockfile
68-
except PidFileError:
69-
raise AssertionError('Lock in use')
70-
finally:
71-
lockfile.close()

test/test_tools.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import json
2-
from unittest.mock import patch, MagicMock
32
import pytest
4-
from stf_appium_client.tools import find_free_port, parse_requirements, lock
5-
from pid import PidFileAlreadyLockedError
3+
from stf_appium_client.tools import find_free_port, parse_requirements
64

75

86
class TestTools:
@@ -30,25 +28,3 @@ def test_parse_requirements(self):
3028
self.assertEqual(parse_requirements("key="), {})
3129
with pytest.raises(ValueError):
3230
self.assertEqual(parse_requirements("="), {})
33-
34-
@patch('stf_appium_client.tools.PidFile')
35-
def test_lock(self, mock_pidfile):
36-
with lock():
37-
self.assertEqual(mock_pidfile.return_value.create.call_count, 1)
38-
self.assertEqual(mock_pidfile.return_value.close.call_count, 0)
39-
self.assertEqual(mock_pidfile.return_value.close.call_count, 1)
40-
41-
@patch('stf_appium_client.tools.PidFile')
42-
def test_lock_is_released(self, mock_pidfile):
43-
try:
44-
with lock():
45-
raise RuntimeError()
46-
except RuntimeError:
47-
self.assertEqual(mock_pidfile.return_value.close.call_count, 1)
48-
49-
@patch('stf_appium_client.tools.PidFile')
50-
def test_lock_in_use(self, mock_pidfile):
51-
mock_pidfile.return_value.create.side_effect = [PidFileAlreadyLockedError()]
52-
with pytest.raises(AssertionError):
53-
with lock():
54-
pass

0 commit comments

Comments
 (0)