Skip to content

Commit

Permalink
Wrap access in Lock
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Nov 3, 2023
1 parent 70678e6 commit 6bf115d
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions tests/unit/synapseclient/core/unit_test_Cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from unittest.mock import patch, call
from collections import OrderedDict
from multiprocessing import Process
from synapseclient.core.lock import Lock

import synapseclient.core.cache as cache
import synapseclient.core.utils as utils
Expand Down Expand Up @@ -569,12 +570,13 @@ def test_cache_item_unmodified_modified_items_is_modified_timestamp(self):
utils.touch(file_path, (new_time_stamp, new_time_stamp))

# THEN we expect the file to be modified
unmodified = my_cache._cache_item_unmodified(
cache_map_entry=my_cache._read_cache_map(
cache_dir=my_cache.get_cache_dir(131201)
).get(file_path),
path=file_path,
)
with Lock(my_cache.cache_map_file_name, dir=my_cache.get_cache_dir(111201)):
unmodified = my_cache._cache_item_unmodified(
cache_map_entry=my_cache._read_cache_map(
cache_dir=my_cache.get_cache_dir(131201)
).get(file_path),
path=file_path,
)
assert unmodified is False

def test_cache_item_unmodified_modified_items_is_modified_timestamp(self):
Expand All @@ -599,12 +601,13 @@ def test_cache_item_unmodified_modified_items_is_modified_timestamp(self):
utils.make_bogus_binary_file(filepath=file_path)

# THEN we expect the file to be modified
unmodified = my_cache._cache_item_unmodified(
cache_map_entry=my_cache._read_cache_map(
cache_dir=my_cache.get_cache_dir(121201)
).get(file_path),
path=file_path,
)
with Lock(my_cache.cache_map_file_name, dir=my_cache.get_cache_dir(111201)):
unmodified = my_cache._cache_item_unmodified(
cache_map_entry=my_cache._read_cache_map(
cache_dir=my_cache.get_cache_dir(121201)
).get(file_path),
path=file_path,
)
assert unmodified is False

def test_cache_item_unmodified_not_modified(self):
Expand All @@ -624,10 +627,11 @@ def test_cache_item_unmodified_not_modified(self):
my_cache.add(file_handle_id=111201, path=file_path)

# THEN we expect the file to be unmodified
unmodified = my_cache._cache_item_unmodified(
cache_map_entry=my_cache._read_cache_map(
cache_dir=my_cache.get_cache_dir(111201)
).get(file_path),
path=file_path,
)
with Lock(my_cache.cache_map_file_name, dir=my_cache.get_cache_dir(111201)):
unmodified = my_cache._cache_item_unmodified(
cache_map_entry=my_cache._read_cache_map(
cache_dir=my_cache.get_cache_dir(111201)
).get(file_path),
path=file_path,
)
assert unmodified is True

0 comments on commit 6bf115d

Please sign in to comment.