This is an automated email from the ASF dual-hosted git repository.

zike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new a5c6dee1 Fix CI can't be failed even the tests are failed (#1367)
a5c6dee1 is described below

commit a5c6dee1af2d693a7db40720b436d05d1228ab51
Author: Zike Yang <z...@apache.org>
AuthorDate: Thu May 15 14:46:14 2025 +0800

    Fix CI can't be failed even the tests are failed (#1367)
    
    ### Motivation
    
    This PR https://github.com/apache/pulsar-client-go/pull/1351 introduced 
some changes but breaked the CI. Currently, even if there are some failed 
tests, the CI won't be failed: 
https://github.com/apache/pulsar-client-go/actions/runs/14973771263/job/42060743359?pr=1364#step:6:9285
    
    The root cause is because it captures the exit status of the tee command 
instead of the go test command. This causes the script to report "Tests passed" 
even when tests actually fail, leading to false positive CI results.
    
    ```
    $TEST_CMD 2>&1 | tee $TEST_LOG
    ```
    
    ### Modification
    
    - Use `set -o pipefail` to correctly capture the exit status of the `go 
test` command in the pipeline
---
 .github/workflows/ci.yml                  |  8 ++++++++
 Makefile                                  |  8 ++++----
 pulsar/reader_test.go                     | 10 ++++++----
 scripts/run-ci-blue-green-cluster.sh      |  1 +
 scripts/run-ci-clustered.sh               |  1 +
 scripts/run-ci-extensible-load-manager.sh |  1 +
 scripts/run-ci.sh                         |  1 +
 7 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aa72fb06..510f1821 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -61,4 +61,12 @@ jobs:
         with:
           go-version: ${{ matrix.go-version }}
       - name: Run Tests
+        id: run-tests
         run: make test GO_VERSION=${{ matrix.go-version }}
+      - name: Upload logs on failure
+        if: failure() && steps.run-tests.outcome == 'failure'
+        uses: actions/upload-artifact@v4
+        with:
+          name: test-logs-${{ matrix.go-version }}
+          path: logs/
+          retention-days: 7
diff --git a/Makefile b/Makefile
index 4ff147c8..3ade7200 100644
--- a/Makefile
+++ b/Makefile
@@ -61,23 +61,23 @@ container:
 test: container test_standalone test_clustered test_extensible_load_manager
 
 test_standalone: container
-       docker run -v /var/run/docker.sock:/var/run/docker.sock 
${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go && ./scripts/run-ci.sh"
+       docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(shell 
pwd)/logs:/pulsar/logs ${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go 
&& ./scripts/run-ci.sh"
 
 test_clustered: container
        PULSAR_VERSION=${PULSAR_VERSION} docker compose -f 
integration-tests/clustered/docker-compose.yml up -d
        until curl http://localhost:8080/metrics > /dev/null 2>&1; do sleep 1; 
done
-       docker run --network=clustered_pulsar ${DOCKER_TEST_ARGS} bash -c "cd 
/pulsar/pulsar-client-go && ./scripts/run-ci-clustered.sh"
+       docker run --network=clustered_pulsar -v $(shell pwd)/logs:/pulsar/logs 
${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go && 
./scripts/run-ci-clustered.sh"
        PULSAR_VERSION=${PULSAR_VERSION} docker compose -f 
integration-tests/clustered/docker-compose.yml down
 
 test_extensible_load_manager: container
        PULSAR_VERSION=${PULSAR_VERSION} docker compose -f 
integration-tests/extensible-load-manager/docker-compose.yml up -d
        until curl http://localhost:8080/metrics > /dev/null 2>&1; do sleep 1; 
done
-       docker run --network=extensible-load-manager_pulsar ${DOCKER_TEST_ARGS} 
bash -c "cd /pulsar/pulsar-client-go && 
./scripts/run-ci-extensible-load-manager.sh"
+       docker run --network=extensible-load-manager_pulsar -v $(shell 
pwd)/logs:/pulsar/logs ${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go 
&& ./scripts/run-ci-extensible-load-manager.sh"
 
        PULSAR_VERSION=${PULSAR_VERSION} docker compose -f 
integration-tests/blue-green/docker-compose.yml up -d
        until curl http://localhost:8081/metrics > /dev/null 2>&1 ; do sleep 1; 
done
 
-       docker run --network=extensible-load-manager_pulsar ${DOCKER_TEST_ARGS} 
bash -c "cd /pulsar/pulsar-client-go && ./scripts/run-ci-blue-green-cluster.sh"
+       docker run --network=extensible-load-manager_pulsar -v $(shell 
pwd)/logs:/pulsar/logs ${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go 
&& ./scripts/run-ci-blue-green-cluster.sh"
        PULSAR_VERSION=${PULSAR_VERSION} docker compose -f 
integration-tests/blue-green/docker-compose.yml down
        PULSAR_VERSION=${PULSAR_VERSION} docker compose -f 
integration-tests/extensible-load-manager/docker-compose.yml down
 
diff --git a/pulsar/reader_test.go b/pulsar/reader_test.go
index 3a74db6c..58c72525 100644
--- a/pulsar/reader_test.go
+++ b/pulsar/reader_test.go
@@ -1031,8 +1031,8 @@ func TestReaderHasNextRetryFailed(t *testing.T) {
                        close(req.doneCh)
                }
        }()
-       minTimer := time.NewTimer(1 * time.Second) // Timer to check if 
r.HasNext() blocked for at least 1s
-       maxTimer := time.NewTimer(3 * time.Second) // Timer to ensure 
r.HasNext() doesn't block for more than 3s
+       maxTimer := time.NewTimer(8 * time.Second) // Timer to ensure 
r.HasNext() doesn't block for more than 3s
+       startTime := time.Now().UnixMilli()
        done := make(chan bool)
        go func() {
                assert.False(t, r.HasNext())
@@ -1043,8 +1043,10 @@ func TestReaderHasNextRetryFailed(t *testing.T) {
        case <-maxTimer.C:
                t.Fatal("r.HasNext() blocked for more than 3s")
        case <-done:
-               assert.False(t, minTimer.Stop(), "r.HasNext() did not block for 
at least 1s")
-               assert.True(t, maxTimer.Stop())
+               now := time.Now().UnixMilli()
+               if now-startTime < 1000 {
+                       t.Fatal("r.HasNext() blocked for less than 1s")
+               }
        }
 
 }
diff --git a/scripts/run-ci-blue-green-cluster.sh 
b/scripts/run-ci-blue-green-cluster.sh
index 8c886db3..21f0e97b 100755
--- a/scripts/run-ci-blue-green-cluster.sh
+++ b/scripts/run-ci-blue-green-cluster.sh
@@ -17,6 +17,7 @@
 # under the License.
 
 set -x
+set -o pipefail
 
 TEST_LOG=/tmp/test-log-$(date +%s).log
 
diff --git a/scripts/run-ci-clustered.sh b/scripts/run-ci-clustered.sh
index a1a0764d..d20ed416 100755
--- a/scripts/run-ci-clustered.sh
+++ b/scripts/run-ci-clustered.sh
@@ -17,6 +17,7 @@
 # under the License.
 
 set -x
+set -o pipefail
 
 TEST_LOG=/tmp/test-log-$(date +%s).log
 
diff --git a/scripts/run-ci-extensible-load-manager.sh 
b/scripts/run-ci-extensible-load-manager.sh
index 714bb4db..3f18d94a 100755
--- a/scripts/run-ci-extensible-load-manager.sh
+++ b/scripts/run-ci-extensible-load-manager.sh
@@ -17,6 +17,7 @@
 # under the License.
 
 set -x
+set -o pipefail
 
 TEST_LOG=/tmp/test-log-$(date +%s).log
 
diff --git a/scripts/run-ci.sh b/scripts/run-ci.sh
index d7ef2eff..2058aa1b 100755
--- a/scripts/run-ci.sh
+++ b/scripts/run-ci.sh
@@ -18,6 +18,7 @@
 
 
 set -x
+set -o pipefail
 
 scripts/pulsar-test-service-start.sh
 

Reply via email to