Skip to content

Commit 4513446

Browse files
committed
Fix CI can't be failed even the tests are failed (#1367)
### Motivation This PR #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 (cherry picked from commit a5c6dee)
1 parent 4595679 commit 4513446

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,12 @@ jobs:
6161
with:
6262
go-version: ${{ matrix.go-version }}
6363
- name: Run Tests
64+
id: run-tests
6465
run: make test GO_VERSION=${{ matrix.go-version }}
66+
- name: Upload logs on failure
67+
if: failure() && steps.run-tests.outcome == 'failure'
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: test-logs-${{ matrix.go-version }}
71+
path: logs/
72+
retention-days: 7

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ container:
6161
test: container test_standalone test_clustered test_extensible_load_manager
6262

6363
test_standalone: container
64-
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"
64+
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"
6565

6666
test_clustered: container
6767
PULSAR_VERSION=${PULSAR_VERSION} docker compose -f integration-tests/clustered/docker-compose.yml up -d
6868
until curl http://localhost:8080/metrics > /dev/null 2>&1; do sleep 1; done
69-
docker run --network=clustered_pulsar ${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go && ./scripts/run-ci-clustered.sh"
69+
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"
7070
PULSAR_VERSION=${PULSAR_VERSION} docker compose -f integration-tests/clustered/docker-compose.yml down
7171

7272
test_extensible_load_manager: container
7373
PULSAR_VERSION=${PULSAR_VERSION} docker compose -f integration-tests/extensible-load-manager/docker-compose.yml up -d
7474
until curl http://localhost:8080/metrics > /dev/null 2>&1; do sleep 1; done
75-
docker run --network=extensible-load-manager_pulsar ${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go && ./scripts/run-ci-extensible-load-manager.sh"
75+
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"
7676

7777
PULSAR_VERSION=${PULSAR_VERSION} docker compose -f integration-tests/blue-green/docker-compose.yml up -d
7878
until curl http://localhost:8081/metrics > /dev/null 2>&1 ; do sleep 1; done
7979

80-
docker run --network=extensible-load-manager_pulsar ${DOCKER_TEST_ARGS} bash -c "cd /pulsar/pulsar-client-go && ./scripts/run-ci-blue-green-cluster.sh"
80+
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"
8181
PULSAR_VERSION=${PULSAR_VERSION} docker compose -f integration-tests/blue-green/docker-compose.yml down
8282
PULSAR_VERSION=${PULSAR_VERSION} docker compose -f integration-tests/extensible-load-manager/docker-compose.yml down
8383

pulsar/reader_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,8 @@ func TestReaderHasNextRetryFailed(t *testing.T) {
10311031
close(req.doneCh)
10321032
}
10331033
}()
1034-
minTimer := time.NewTimer(1 * time.Second) // Timer to check if r.HasNext() blocked for at least 1s
1035-
maxTimer := time.NewTimer(3 * time.Second) // Timer to ensure r.HasNext() doesn't block for more than 3s
1034+
maxTimer := time.NewTimer(8 * time.Second) // Timer to ensure r.HasNext() doesn't block for more than 3s
1035+
startTime := time.Now().UnixMilli()
10361036
done := make(chan bool)
10371037
go func() {
10381038
assert.False(t, r.HasNext())
@@ -1043,8 +1043,10 @@ func TestReaderHasNextRetryFailed(t *testing.T) {
10431043
case <-maxTimer.C:
10441044
t.Fatal("r.HasNext() blocked for more than 3s")
10451045
case <-done:
1046-
assert.False(t, minTimer.Stop(), "r.HasNext() did not block for at least 1s")
1047-
assert.True(t, maxTimer.Stop())
1046+
now := time.Now().UnixMilli()
1047+
if now-startTime < 1000 {
1048+
t.Fatal("r.HasNext() blocked for less than 1s")
1049+
}
10481050
}
10491051

10501052
}

scripts/run-ci-blue-green-cluster.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# under the License.
1818

1919
set -x
20+
set -o pipefail
2021

2122
TEST_LOG=/tmp/test-log-$(date +%s).log
2223

scripts/run-ci-clustered.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# under the License.
1818

1919
set -x
20+
set -o pipefail
2021

2122
TEST_LOG=/tmp/test-log-$(date +%s).log
2223

scripts/run-ci-extensible-load-manager.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# under the License.
1818

1919
set -x
20+
set -o pipefail
2021

2122
TEST_LOG=/tmp/test-log-$(date +%s).log
2223

scripts/run-ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
set -x
21+
set -o pipefail
2122

2223
scripts/pulsar-test-service-start.sh
2324

0 commit comments

Comments
 (0)