From 18cbba5b4e23fd617996ee939c90e1659caf9005 Mon Sep 17 00:00:00 2001 From: Reshmi Date: Mon, 29 Jun 2026 16:54:32 +0530 Subject: [PATCH 1/3] fix publish build info build duration issue --- buildinfo_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ go.mod | 2 ++ go.sum | 4 ++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/buildinfo_test.go b/buildinfo_test.go index 6c95699c2..96ae9768d 100644 --- a/buildinfo_test.go +++ b/buildinfo_test.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "testing" + "time" "github.com/jfrog/jfrog-cli-artifactory/artifactory/formats" clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests" @@ -664,6 +665,45 @@ func TestArtifactoryBuildCollectEnv(t *testing.T) { cleanArtifactoryTest() } +func TestArtifactoryBuildPublishRecordsDuration(t *testing.T) { + initArtifactoryTest(t, "") + buildNumber := "13" + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + + // First build command - records the build's start time. + uploadFiles(t, "upload", "--build-name="+tests.RtBuildName1, "--build-number="+buildNumber) + + // Collect environment, then let a measurable amount of time pass before publishing, + // so the recorded duration is deterministically greater than zero. + assert.NoError(t, artifactoryCli.WithoutCredentials().Exec("bce", tests.RtBuildName1, buildNumber)) + elapsed := 2 * time.Second + time.Sleep(elapsed) + + // Publish the build info. + runRt(t, "bp", tests.RtBuildName1, buildNumber) + + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumber) + if err != nil { + assert.NoError(t, err) + return + } + if !found { + assert.True(t, found, "build info was expected to be found") + return + } + buildInfo := publishedBuildInfo.BuildInfo + + // The build must have a recorded start time and a non-zero duration covering at least the sleep. + assert.NotEmpty(t, buildInfo.Started, "build info should have a 'started' timestamp") + assert.Greater(t, buildInfo.DurationMillis, int64(0), "build duration should not be published as 0") + assert.GreaterOrEqual(t, buildInfo.DurationMillis, elapsed.Milliseconds(), + "build duration should cover the elapsed time between the first build command and publish") + + // Cleanup + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + cleanArtifactoryTest() +} + func TestBuildAddGit(t *testing.T) { testBuildAddGit(t, false) } diff --git a/go.mod b/go.mod index d176a3ec5..e796fb20b 100644 --- a/go.mod +++ b/go.mod @@ -242,6 +242,8 @@ require ( sigs.k8s.io/yaml v1.6.0 // indirect ) +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.13.1-0.20260629061854-cd4824207c01 + //replace github.com/gfleury/go-bitbucket-v1 => github.com/gfleury/go-bitbucket-v1 v0.0.0-20230825095122-9bc1711434ab //replace github.com/ktrysmt/go-bitbucket => github.com/ktrysmt/go-bitbucket v0.9.80 diff --git a/go.sum b/go.sum index 31d45dac2..e3f3e1581 100644 --- a/go.sum +++ b/go.sum @@ -394,8 +394,8 @@ github.com/jellydator/ttlcache/v3 v3.4.0 h1:YS4P125qQS0tNhtL6aeYkheEaB/m8HCqdMMP github.com/jellydator/ttlcache/v3 v3.4.0/go.mod h1:Hw9EgjymziQD3yGsQdf1FqFdpp7YjFMd4Srg5EJlgD4= github.com/jfrog/archiver/v3 v3.6.3 h1:hkAmPjBw393tPmQ07JknLNWFNZjXdy2xFEnOW9wwOxI= github.com/jfrog/archiver/v3 v3.6.3/go.mod h1:5V9l+Fte30Y4qe9dUOAd3yNTf8lmtVNuhKNrvI8PMhg= -github.com/jfrog/build-info-go v1.13.1-0.20260615080618-42488b58c305 h1:q7/hTPm6ibQf45CztScTgPb8cAmKIeQ9im0ClISsq7Y= -github.com/jfrog/build-info-go v1.13.1-0.20260615080618-42488b58c305/go.mod h1:CYRUCvLKfyARjoJXLWAxce1qNUxTEtbRKAARkV42vpE= +github.com/jfrog/build-info-go v1.13.1-0.20260629061854-cd4824207c01 h1:PY/XBglBZvwSyKgFUMj7mJ62tm72ZFLizDOHGC7ORJI= +github.com/jfrog/build-info-go v1.13.1-0.20260629061854-cd4824207c01/go.mod h1:CYRUCvLKfyARjoJXLWAxce1qNUxTEtbRKAARkV42vpE= github.com/jfrog/froggit-go v1.22.0 h1:eeN5F8sOUo+h2cXkzArAu4nvSdjkDTAZtgqwrct70qg= github.com/jfrog/froggit-go v1.22.0/go.mod h1:wRDryqyp3oe+eHgME2mpnEQmO8XBECIPagFwj0nHmdI= github.com/jfrog/go-mockhttp v0.3.1 h1:/wac8v4GMZx62viZmv4wazB5GNKs+GxawuS1u3maJH8= From 91e51e8ca7efa26eb091059a442557de0b211c1d Mon Sep 17 00:00:00 2001 From: Reshmi Date: Thu, 2 Jul 2026 20:08:43 +0530 Subject: [PATCH 2/3] refactor testcase --- buildinfo_test.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/buildinfo_test.go b/buildinfo_test.go index 96ae9768d..202056aab 100644 --- a/buildinfo_test.go +++ b/buildinfo_test.go @@ -667,19 +667,14 @@ func TestArtifactoryBuildCollectEnv(t *testing.T) { func TestArtifactoryBuildPublishRecordsDuration(t *testing.T) { initArtifactoryTest(t, "") - buildNumber := "13" + // Use a unique build number to avoid clashing with other tests that reuse RtBuildName1. + buildNumber := strconv.FormatInt(time.Now().Unix(), 10) inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) // First build command - records the build's start time. uploadFiles(t, "upload", "--build-name="+tests.RtBuildName1, "--build-number="+buildNumber) - - // Collect environment, then let a measurable amount of time pass before publishing, - // so the recorded duration is deterministically greater than zero. + // Collect environment, mirroring the reported scenario (upload -> bce -> bp). assert.NoError(t, artifactoryCli.WithoutCredentials().Exec("bce", tests.RtBuildName1, buildNumber)) - elapsed := 2 * time.Second - time.Sleep(elapsed) - - // Publish the build info. runRt(t, "bp", tests.RtBuildName1, buildNumber) publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumber) @@ -693,11 +688,8 @@ func TestArtifactoryBuildPublishRecordsDuration(t *testing.T) { } buildInfo := publishedBuildInfo.BuildInfo - // The build must have a recorded start time and a non-zero duration covering at least the sleep. assert.NotEmpty(t, buildInfo.Started, "build info should have a 'started' timestamp") assert.Greater(t, buildInfo.DurationMillis, int64(0), "build duration should not be published as 0") - assert.GreaterOrEqual(t, buildInfo.DurationMillis, elapsed.Milliseconds(), - "build duration should cover the elapsed time between the first build command and publish") // Cleanup inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) From 1685263af05ef10f45b22a18a819959225206e12 Mon Sep 17 00:00:00 2001 From: Reshmi Date: Thu, 2 Jul 2026 20:28:40 +0530 Subject: [PATCH 3/3] update deps --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 89dcd2e62..99704c780 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,8 @@ github.com/jfrog/archiver/v3 v3.6.3 h1:hkAmPjBw393tPmQ07JknLNWFNZjXdy2xFEnOW9wwO github.com/jfrog/archiver/v3 v3.6.3/go.mod h1:5V9l+Fte30Y4qe9dUOAd3yNTf8lmtVNuhKNrvI8PMhg= github.com/jfrog/build-info-go v1.13.1-0.20260629061854-cd4824207c01 h1:PY/XBglBZvwSyKgFUMj7mJ62tm72ZFLizDOHGC7ORJI= github.com/jfrog/build-info-go v1.13.1-0.20260629061854-cd4824207c01/go.mod h1:CYRUCvLKfyARjoJXLWAxce1qNUxTEtbRKAARkV42vpE= -github.com/jfrog/froggit-go v1.22.0 h1:eeN5F8sOUo+h2cXkzArAu4nvSdjkDTAZtgqwrct70qg= -github.com/jfrog/froggit-go v1.22.0/go.mod h1:wRDryqyp3oe+eHgME2mpnEQmO8XBECIPagFwj0nHmdI= +github.com/jfrog/froggit-go v1.23.0 h1:HGNIP9ZqoXKXHQONazhCENqIrFLfc8J3aX/F0QelQ2s= +github.com/jfrog/froggit-go v1.23.0/go.mod h1:wRDryqyp3oe+eHgME2mpnEQmO8XBECIPagFwj0nHmdI= github.com/jfrog/go-mockhttp v0.3.1 h1:/wac8v4GMZx62viZmv4wazB5GNKs+GxawuS1u3maJH8= github.com/jfrog/go-mockhttp v0.3.1/go.mod h1:LmKHex73SUZswM8ANS8kPxLihTOvtq44HVcCoTJKuqc= github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=