Skip to content

Commit

Permalink
Disable locks by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Aug 15, 2023
1 parent add4366 commit 39f238f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
16 changes: 8 additions & 8 deletions deeplake/core/tests/test_locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ def __exit__(self, *args, **kwargs):
def test_dataset_locking(ds_generator):
deeplake.constants.LOCK_LOCAL_DATASETS = True
try:
ds = ds_generator()
ds = ds_generator(lock_enabled=True)
ds.create_tensor("x")
arr = np.random.random((32, 32))
ds.x.append(arr)

with VM():
# Make sure read only warning is raised
with pytest.warns(UserWarning):
ds = ds_generator()
ds = ds_generator(lock_enabled=True)
np.testing.assert_array_equal(arr, ds.x[0].numpy())
assert ds.read_only == True
with pytest.raises(LockedException):
ds.read_only = False
# Raise error if user explicitly asks for write access
with pytest.raises(LockedException):
ds = ds_generator(read_only=False)
ds = ds_generator(read_only=False, lock_enabled=True)
# No warnings if user requests read only mode
with warnings.catch_warnings(record=True) as ws:
ds = ds_generator(read_only=True)
ds = ds_generator(read_only=True, lock_enabled=True)
np.testing.assert_array_equal(arr, ds.x[0].numpy())
assert not ws
finally:
Expand All @@ -74,15 +74,15 @@ def test_dataset_locking(ds_generator):
def test_vc_locking(ds_generator):
deeplake.constants.LOCK_LOCAL_DATASETS = True
try:
ds = ds_generator()
ds = ds_generator(lock_enabled=True)
ds.create_tensor("x")
arr = np.random.random((32, 32))
ds.x.append(arr)
ds.commit()
ds.checkout("branch", create=True)
with VM():
with warnings.catch_warnings(record=True) as ws:
ds = ds_generator()
ds = ds_generator(lock_enabled=True)
np.testing.assert_array_equal(arr, ds.x[0].numpy())
assert not ws, str(ws[0])
finally:
Expand All @@ -99,15 +99,15 @@ def nlocks():
assert len(locks) == len(refs)
return len(locks) - nlocks_previous

ds = s3_ds_generator()
ds = s3_ds_generator(lock_enabled=True)
ds.create_tensor("a")
assert nlocks() == 1

ds.__del__() # Note: investigate why this doesnt happen automatically. (cyclic refs?)
del ds
assert nlocks() == 0

ds = s3_ds_generator()
ds = s3_ds_generator(lock_enabled=True)
ds.create_tensor("x")
ds.x.extend(np.random.random((2, 32)))
views = []
Expand Down
28 changes: 26 additions & 2 deletions deeplake/tests/dataset_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def local_auth_ds(local_auth_ds_generator):
@pytest.fixture
def local_ds_generator(local_path):
def generate_local_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

return deeplake.dataset(local_path, **kwargs)

return generate_local_ds
Expand All @@ -85,6 +88,9 @@ def generate_local_ds(**kwargs):
@pytest.fixture
def local_auth_ds_generator(local_path, hub_cloud_dev_token):
def generate_local_auth_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

return deeplake.dataset(local_path, token=hub_cloud_dev_token, **kwargs)

return generate_local_auth_ds
Expand All @@ -98,6 +104,9 @@ def s3_ds(s3_ds_generator):
@pytest.fixture
def s3_ds_generator(s3_path):
def generate_s3_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

return deeplake.dataset(s3_path, **kwargs)

return generate_s3_ds
Expand All @@ -110,8 +119,11 @@ def gdrive_ds(gdrive_ds_generator):

@pytest.fixture
def gdrive_ds_generator(gdrive_path, gdrive_creds):
def generate_gdrive_ds():
return deeplake.dataset(gdrive_path, creds=gdrive_creds)
def generate_gdrive_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

return deeplake.dataset(gdrive_path, creds=gdrive_creds, **kwargs)

return generate_gdrive_ds

Expand All @@ -124,6 +136,9 @@ def gcs_ds(gcs_ds_generator):
@pytest.fixture
def gcs_ds_generator(gcs_path, gcs_creds):
def generate_gcs_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

return deeplake.dataset(gcs_path, creds=gcs_creds, **kwargs)

return generate_gcs_ds
Expand All @@ -137,6 +152,9 @@ def azure_ds(azure_ds_generator):
@pytest.fixture
def azure_ds_generator(azure_path):
def generate_azure_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

return deeplake.dataset(azure_path, **kwargs)

return generate_azure_ds
Expand All @@ -150,6 +168,9 @@ def hub_cloud_ds(hub_cloud_ds_generator):
@pytest.fixture
def hub_cloud_ds_generator(hub_cloud_path, hub_cloud_dev_token):
def generate_hub_cloud_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

Check warning on line 172 in deeplake/tests/dataset_fixtures.py

View check run for this annotation

Codecov / codecov/patch

deeplake/tests/dataset_fixtures.py#L171-L172

Added lines #L171 - L172 were not covered by tests

return deeplake.dataset(hub_cloud_path, token=hub_cloud_dev_token, **kwargs)

return generate_hub_cloud_ds
Expand All @@ -158,6 +179,9 @@ def generate_hub_cloud_ds(**kwargs):
@pytest.fixture
def hub_cloud_gcs_ds_generator(gcs_path, gcs_creds, hub_cloud_dev_token):
def generate_hub_cloud_gcs_ds(**kwargs):
if kwargs.get("lock_enabled") is None:
kwargs["lock_enabled"] = False

Check warning on line 183 in deeplake/tests/dataset_fixtures.py

View check run for this annotation

Codecov / codecov/patch

deeplake/tests/dataset_fixtures.py#L182-L183

Added lines #L182 - L183 were not covered by tests

ds = deeplake.dataset(gcs_path, creds=gcs_creds, **kwargs)
ds.connect(
org_id=HUB_CLOUD_DEV_USERNAME,
Expand Down

0 comments on commit 39f238f

Please sign in to comment.