Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
CORTX-33673: push multi thread testing program in test folder
Browse files Browse the repository at this point in the history
Signed-off-by: Tanuja Shinde <tanuja.shinde@seagate.com>
  • Loading branch information
tanujashinde0405 committed Aug 11, 2022
1 parent 8eb91d4 commit e84db05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
14 changes: 7 additions & 7 deletions py-utils/src/utils/conf_store/conf_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ def lock(self, index: str, **kwargs):
if key == 'duration' and not isinstance(val, int):
raise ConfError(errno.EINVAL, "Invalid value %s for parameter %s", val, key)

owner = self._lock_owner if 'owner' not in kwargs.keys() else kwargs['owner']
domain = self._lock_domain if 'domain' not in kwargs.keys() else kwargs['domain']
duration = self._lock_duration if 'duration' not in kwargs.keys() else kwargs['duration']
owner = self._lock_owner if 'owner' not in kwargs else kwargs['owner']
domain = self._lock_domain if 'domain' not in kwargs else kwargs['domain']
duration = self._lock_duration if 'duration' not in kwargs else kwargs['duration']

rc = False
if self.test_lock(index, owner=owner, domain=domain):
Expand Down Expand Up @@ -339,8 +339,8 @@ def unlock(self, index: str, **kwargs):
if key == 'force' and not isinstance(val, bool):
raise ConfError(errno.EINVAL, "Invalid value %s for parameter %s", val, key)

owner = self._lock_owner if 'owner' not in kwargs.keys() else kwargs['owner']
domain = self._lock_domain if 'domain' not in kwargs.keys() else kwargs['domain']
owner = self._lock_owner if 'owner' not in kwargs else kwargs['owner']
domain = self._lock_domain if 'domain' not in kwargs else kwargs['domain']

rc = False
if self.get(index, const.LOCK_OWNER_KEY_PREFIX % domain) == owner or force:
Expand Down Expand Up @@ -369,8 +369,8 @@ def test_lock(self, index: str, **kwargs):
if key not in allowed_keys:
raise ConfError(errno.EINVAL, "Invalid parameter %s", key)

owner = self._lock_owner if 'owner' not in kwargs.keys() else kwargs['owner']
domain = self._lock_domain if 'domain' not in kwargs.keys() else kwargs['domain']
owner = self._lock_owner if 'owner' not in kwargs else kwargs['owner']
domain = self._lock_domain if 'domain' not in kwargs else kwargs['domain']

_current_owner= self.get(index, const.LOCK_OWNER_KEY_PREFIX % domain)
if _current_owner in [None, "", owner]:
Expand Down
18 changes: 8 additions & 10 deletions py-utils/test/conf_store/test_conf_store_multiple_lock_threads.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import sys
from multiprocessing import Process
import random
from datetime import datetime
Expand All @@ -10,11 +8,11 @@
class TestConfStoreLock(object):
"""Test Confstore lock."""
lock_status = []
def __init__(self, URL="consul://ssc-vm-g3-rhev4-3306.colo.seagate.com/conf10"):
def __init__(self, URL="consul://cortx-consul-server:8500/test_lock"):
self.url = URL
self.duration = 20

def test_lock_race(self, thread_count:int=2, repeat=1):
def test_lock_race(self, thread_count:int = 2, repeat = 1):
"""Test race condition with lock."""
_index = None
_conf_index = TestConfStoreLock._generate_index()
Expand All @@ -28,7 +26,7 @@ def test_lock_race(self, thread_count:int=2, repeat=1):
for _proc in _process_store:
_proc.start()

def test_multiple_lock_unlock(self, thread_count:int=2, repeat=1):
def test_multiple_lock_unlock(self, thread_count:int = 2, repeat = 1):
"""Test race condition with lock."""
_index = None
_conf_index = TestConfStoreLock._generate_index()
Expand All @@ -38,11 +36,11 @@ def test_multiple_lock_unlock(self, thread_count:int=2, repeat=1):
Conf.load(_index, self.url)
_conf_process = Process(target=self.lock_unlock, args=(_index, repeat), kwargs={ "owner": _index, "duration":self.duration})
_process_store.append(_conf_process)

for _proc in _process_store:
_proc.start()
_proc.join()

def test_multiple_lock_reset_lock(self, thread_count:int = 2, repeat = 1):
"""Test race condition with lock."""
_index = None
Expand All @@ -53,7 +51,7 @@ def test_multiple_lock_reset_lock(self, thread_count:int = 2, repeat = 1):
Conf.load(_index, self.url)
_conf_process = Process(target=self.lock_reset_lock, args=(_index, repeat), kwargs={ "owner": _index })
_process_store.append(_conf_process)

for _proc in _process_store:
_proc.start()
_proc.join()
Expand Down Expand Up @@ -108,7 +106,7 @@ def lock_unlock(self, index, repeat, **kwargs):
self.do_lock(index, 1, **kwargs)
sleep(1)
self.do_unlock(index, 1)

def lock_reset_lock(self, index, repeat, **kwargs):
for rep in range(0, repeat):
print(f"Rep {index} {rep+1}")
Expand All @@ -125,7 +123,7 @@ def lock_and_test_lock(self, index, repeat, **kwargs):
self.do_unlock(index,1)
sleep(1)
self._test_lock(index, 1)

def _test_lock(self, index, repeat):
for rep in range(0, repeat):
print(f"Test Lock Rep {index} {rep+1}")
Expand Down

0 comments on commit e84db05

Please sign in to comment.