From f17d90fadf9014b1c9762db087602cc5c4b23e6c Mon Sep 17 00:00:00 2001 From: Shuaiyi Date: Mon, 15 Jan 2024 02:39:01 -0800 Subject: [PATCH] Log ensureArtifact ConflictErr (#19294) * Log ensureArtifact ConflictErr Signed-off-by: Shuaiyi Liu * Log ensureArtifact ConflictErr Signed-off-by: Shuaiyi Liu --------- Signed-off-by: Shuaiyi Liu Co-authored-by: Wang Yan --- src/controller/artifact/controller.go | 1 + src/controller/artifact/controller_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/controller/artifact/controller.go b/src/controller/artifact/controller.go index 5a11a8e1c..0e710c064 100644 --- a/src/controller/artifact/controller.go +++ b/src/controller/artifact/controller.go @@ -227,6 +227,7 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri if !errors.IsConflictErr(err) { return false, nil, err } + log.Debugf("failed to create artifact %s@%s: %v", repository, digest, err) // if got conflict error, try to get the artifact again artifact, err = c.artMgr.GetByDigest(ctx, repository, digest) if err != nil { diff --git a/src/controller/artifact/controller_test.go b/src/controller/artifact/controller_test.go index 167dc84e5..ce58b5d28 100644 --- a/src/controller/artifact/controller_test.go +++ b/src/controller/artifact/controller_test.go @@ -237,6 +237,21 @@ func (c *controllerTestSuite) TestEnsureArtifact() { c.Require().Nil(err) c.True(created) c.Equal(int64(1), art.ID) + + // reset the mock + c.SetupTest() + + // the artifact doesn't exist and get a conflict error on creating the artifact and fail to get again + c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{ + ProjectID: 1, + }, nil) + c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil)) + c.artMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), errors.ConflictError(nil)) + c.abstractor.On("AbstractMetadata").Return(nil) + created, art, err = c.ctl.ensureArtifact(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", digest) + c.Require().Error(err, errors.NotFoundError(nil)) + c.False(created) + c.Require().Nil(art) } func (c *controllerTestSuite) TestEnsure() {