Skip to content

Commit

Permalink
Log ensureArtifact ConflictErr
Browse files Browse the repository at this point in the history
Signed-off-by: Shuaiyi Liu <[email protected]>
  • Loading branch information
LiuShuaiyi authored and chlins committed Oct 13, 2023
1 parent f9ab185 commit b37e517
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/controller/artifact/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: %v", err)
// if got conflict error, try to get the artifact again
artifact, err = c.artMgr.GetByDigest(ctx, repository, digest)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions src/controller/artifact/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b37e517

Please sign in to comment.