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

feat(gRPC): implement BidiWriteObject #586

Merged
merged 10 commits into from
Feb 16, 2024
Merged

Conversation

cojenco
Copy link
Contributor

@cojenco cojenco commented Jan 24, 2024

Fixes #568

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8480153) 98.60% compared to head (47ec9fe) 98.63%.
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #586      +/-   ##
==========================================
+ Coverage   98.60%   98.63%   +0.03%     
==========================================
  Files          50       50              
  Lines        8072     8284     +212     
==========================================
+ Hits         7959     8171     +212     
  Misses        113      113              
Flag Coverage Δ
unittests 98.63% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cojenco cojenco marked this pull request as ready for review January 25, 2024 22:26
@cojenco cojenco requested review from coryan and a team as code owners January 25, 2024 22:26
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of optional things and a question.

gcs/upload.py Show resolved Hide resolved
tests/test_upload.py Outdated Show resolved Hide resolved
tests/test_upload.py Show resolved Hide resolved
gcs/upload.py Outdated Show resolved Hide resolved
gcs/upload.py Outdated Show resolved Hide resolved
persisted_size=len(upload.media)
)

if upload is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking this after doing upload.media += content seems like a bug.

Seems like this check should be around line 350 or so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle cases with missing BidiWriteObjectRequest. I probably went overboard, and there's also a test case for this gcs.upload.Upload.process_bidi_write_object_grpc(db, [], context)

def test_init_object_write_grpc_empty(self):
db = unittest.mock.Mock()
context = self.mock_context()
upload, _ = gcs.upload.Upload.init_write_object_grpc(db, [], context)
self.assertIsNone(upload)
context.abort.assert_called_once_with(
grpc.StatusCode.INVALID_ARGUMENT, unittest.mock.ANY
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but if upload is None then line 359 would have raised an exception before you got here, right? You probably want to detect the problem before the first use of upload. Did I miss something? If so, please just merge, otherwise please reorder the test to prevent crashes exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the request loop on L307, we're checking if upload is None before the first use.

This extra check is outside the request loop. It covers the rare case of missing requests, and prevents crashes in the attempt to finalize an upload

gcs/upload.py Outdated Show resolved Hide resolved
persisted_size=len(upload.media)
)

if upload is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but if upload is None then line 359 would have raised an exception before you got here, right? You probably want to detect the problem before the first use of upload. Did I miss something? If so, please just merge, otherwise please reorder the test to prevent crashes exceptions.

gcs/upload.py Outdated Show resolved Hide resolved
@cojenco cojenco merged commit 5267c9d into googleapis:main Feb 16, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement bidirectional writes in GRPC
2 participants