Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure dircache on ls #612

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading