Skip to content

Commit

Permalink
Ensure dircache on ls (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant authored Mar 8, 2024
1 parent 1658976 commit 88d445f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ async def _list_objects(self, path, prefix="", versions=False, **kwargs):

# Don't cache prefixed/partial listings, in addition to
# not using the inventory report service to do listing directly.
if not prefix and use_snapshot_listing is False:
if not prefix and not use_snapshot_listing:
self.dircache[path] = out
return out

Expand Down
16 changes: 9 additions & 7 deletions gcsfs/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ class ChecksumError(Exception):
)


errs = list(range(500, 505)) + [
# Request Timeout
408,
# Too Many Requests
429,
]
errs = set(errs + [str(e) for e in errs])


def is_retriable(exception):
"""Returns True if this exception is retriable."""
errs = list(range(500, 505)) + [
# Request Timeout
408,
# Too Many Requests
429,
]
errs += [str(e) for e in errs]
if isinstance(exception, HttpError):
return exception.code in errs

Expand Down
19 changes: 17 additions & 2 deletions gcsfs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,27 @@
TEST_REQUESTER_PAYS_BUCKET = gcsfs.tests.settings.TEST_REQUESTER_PAYS_BUCKET


def test_simple(gcs):
assert not GoogleCredentials.tokens
def test_simple(gcs, monkeypatch):
monkeypatch.setattr(GoogleCredentials, "tokens", None)
gcs.ls(TEST_BUCKET) # no error
gcs.ls("/" + TEST_BUCKET) # OK to lead with '/'


def test_dircache_filled(gcs):
assert not dict(gcs.dircache)
gcs.ls(TEST_BUCKET)
assert len(gcs.dircache) == 1
gcs.dircache[TEST_BUCKET][0]["CHECK"] = True
out = gcs.ls(TEST_BUCKET, detail=True)
assert [o for o in out if o.get("CHECK", None)]

gcs.invalidate_cache()
assert not dict(gcs.dircache)

gcs.find(TEST_BUCKET)
assert len(gcs.dircache)


def test_many_connect(docker_gcs):
from multiprocessing.pool import ThreadPool

Expand Down

0 comments on commit 88d445f

Please sign in to comment.