Repository navigation
testing: replace legacy gopkg.in/check.v1 - #4185
Conversation
| awriter, err := suite.StorageDriver.Writer(suite.ctx, filename, true) | ||
| c.Assert(err, check.IsNil) | ||
| suite.Require().NoError(err) |
There was a problem hiding this comment.
TestWriteZeroByteStreamThenAppend is currently failing for S3 driver. The filename does exist but suite.StorageDriver.Writer returns s3aws: Path not found error.
=== RUN TestS3DriverSuite/TestWriteZeroByteContentThenAppend
testsuites.go:561:
Error Trace: /home/runner/work/distribution/distribution/registry/storage/driver/testsuites/testsuites.go:561
Error: Received unexpected error:
s3aws: Path not found: /kj90ph.80.nh8il2_o0_wieqfycj/u2
Test: TestS3DriverSuite/TestWriteZeroByteContentThenAppend
There was a problem hiding this comment.
@Juneezee this looks to have this same root cause as the issue we resolved here: https://gitlab.com/gitlab-org/container-registry/-/merge_requests/20, namely:
The registry S3 storage driver uses multipart uploads for streaming. Multipart uploads require at least 1 chunk, so it doesn’t work for 0B files (0 chunks).
The same is true for instantiating the writer when append is set to true.
There was a problem hiding this comment.
The GitLab container registry "resolved" it by skipping a benchmark. This is a unit test. All the other storage drivers pass this test. Code which consumes the storage driver interface may therefore depend on the behaviour asserted by this test. The s3 driver is not upholding the contract, therefore the driver contains a bug which needs fixing.
There was a problem hiding this comment.
I agree, S3 should conform to expectations here, the linked MR demonstrates a likely root cause, even if it wasn't addressed at the time.
There was a problem hiding this comment.
I've played around with this on my personal AWS account and it has revived an unpleasant AWS S3 memory for me 🫠
When you initiate a multipart upload to S3, it first creates an upload "record" but does not actually upload any object data. Those are uploaded as parts. So for an empty 0 byte file, no object content is uploaded, just the metadata for the initiated upload record is stored. We actually handle this edge case in the S3 driver by uploading an empty part. I'm wondering if that's actually the problem here, but I'm not sure 🤷♂️
What's happening inTestWriteZeroByteStreamThenAppend test is:
- We create a multipart upload when the non-
appendModewriter is created:distribution/registry/storage/driver/s3-aws/s3.go
Lines 685 to 695 in 04e3bda
- We then commit and write the empty part (
CommitandClosecalls actually lead to this call)distribution/registry/storage/driver/s3-aws/s3.go
Line 1583 in 04e3bda
- We then try to list multipart uploads when we create the
appendModewriter here: That call returns noUploadsbecause there are no pending uploads since the one we had created earlier has been successfully completed via theCommit. TheWritecall actuallybreaks here:which then ends up with the Not Found path error returned here:distribution/registry/storage/driver/s3-aws/s3.go
Lines 715 to 717 in 04e3bda
I feel like I'm missing some S3 multipart uploads knowledge despite trawling through their docs. I wrote a simple Go program that verifies that completed uploads are not returned in the list multipart uploads, only the ongoing ones:
see this gist (just remove the svc.CompleteMultipartUploadWithContext call and you'll see your pending upload returned in the list call -- make sure you change the key to something that's not uploaded yet)
If this is really the correct behaviour then I struggle to see how the TestWriteZeroByteStreamThenAppend can ever pass 🤔 I also might be overlooking something, so more heads looking into this would be helpful 😄
There was a problem hiding this comment.
With the diff I pasted above, all tests pass. Can push to this branch once we've agreed on what we should return.
Nice! I would argue that the behavior of appending after commit is implementation dependent rather than "true" undefined behavior, so I'm in favor of an error specific to S3.
There was a problem hiding this comment.
That looks good except for the comment mentioning ErrUnsupportedMethod: 4baddbc#diff-42ab115e8f2c28fa837e174c081ffe3542e13f5fbd58271f06b179c1123c7905R685
There was a problem hiding this comment.
Arrrrgh, that was in the original code I never cleaned up after we discussed it. Ok should be fixed now 3f3e61e
corhere
left a comment
There was a problem hiding this comment.
Thanks for working on this!
|
Thanks for all the helpful comments ❤️ ! |
| awriter, err := suite.StorageDriver.Writer(suite.ctx, filename, true) | ||
| c.Assert(err, check.IsNil) | ||
| suite.Require().NoError(err) |
There was a problem hiding this comment.
The GitLab container registry "resolved" it by skipping a benchmark. This is a unit test. All the other storage drivers pass this test. Code which consumes the storage driver interface may therefore depend on the behaviour asserted by this test. The s3 driver is not upholding the contract, therefore the driver contains a bug which needs fixing.
|
I will rebase and resolve conflicts when this PR is ready to merge. |
|
Arrrrrrrrrrgh conflicts |
This commit replaces the legacy `gopkg.in/check.v1` testing dependency with `github.com/stretchr/testify`. Closes #3884. Signed-off-by: Eng Zer Jun <[email protected]>
This commit apply the following suggestions: 1. #4185 (comment) 2. #4185 (comment) 3. #4185 (comment) 4. #4185 (comment) Signed-off-by: Eng Zer Jun <[email protected]>
This commit apply the following suggestions: 1. #4185 (comment) 2. #4185 (comment) 3. #4185 (comment) 4. #4185 (comment) Signed-off-by: Eng Zer Jun <[email protected]>
This commit updates (writer).Writer() method in S3 storage driver to handle the case where an append is attempted to a zer-size content. S3 does not allow appending to already committed content, so we are optiing to provide the following case as a narrowed down behaviour: Writer can only append to zero byte content - in that case, a new S3 MultipartUpload is created that will be used for overriding the already committed zero size content. Appending to non-zero size content fails with error. Co-authored-by: Cory Snider <[email protected]> Signed-off-by: Milos Gajdos <[email protected]>
|
Alright, PTAL @corhere @deleteriousEffect @thaJeztah |
Signed-off-by: Milos Gajdos <[email protected]>
|
@corhere we can't merge this without your approval. Anything you want to add to this? |
This PR replaces the legacy
gopkg.in/check.v1testing dependency withgithub.com/stretchr/testify.Closes #3884.