From 1e3f1bded3c321ba65abb5af522d2922cefa711a Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Wed, 21 Apr 2021 18:13:30 +0300 Subject: [PATCH 1/6] Reduce the number of parallel workers for running cpp tests --- pulsar-client-cpp/run-unit-tests.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pulsar-client-cpp/run-unit-tests.sh b/pulsar-client-cpp/run-unit-tests.sh index 5dcab893529e9..dc46189f4c2da 100755 --- a/pulsar-client-cpp/run-unit-tests.sh +++ b/pulsar-client-cpp/run-unit-tests.sh @@ -28,13 +28,20 @@ cd $ROOT_DIR/pulsar-client-cpp pushd tests if [ -f /gtest-parallel/gtest-parallel ]; then - echo "---- Run unit tests in parallel" + gtest_workers=10 + # use nproc to set workers to 2 x the number of available cores if nproc is available + if [ -x "$(command -v nproc)" ]; then + gtest_workers=$(( $(nproc) * 2 )) + fi + # set maximum workers to 10 + gtest_workers=$(( gtest_workers > 10 ? 10 : gtest_workers )) + echo "---- Run unit tests in parallel (workers=$gtest_workers)" tests="" if [ $# -eq 1 ]; then tests="--gtest_filter=$1" echo "Running tests: $1" fi - /gtest-parallel/gtest-parallel ./main $tests --workers=10 + /gtest-parallel/gtest-parallel ./main $tests --workers=$gtest_workers RES=$? else ./main From 0ac89297e1f2ba9237d4cd5c092f8f50d869cf82 Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Wed, 21 Apr 2021 18:14:09 +0300 Subject: [PATCH 2/6] Store logs for gtests --- pulsar-client-cpp/run-unit-tests.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pulsar-client-cpp/run-unit-tests.sh b/pulsar-client-cpp/run-unit-tests.sh index dc46189f4c2da..7e40a496a9aae 100755 --- a/pulsar-client-cpp/run-unit-tests.sh +++ b/pulsar-client-cpp/run-unit-tests.sh @@ -27,6 +27,8 @@ cd $ROOT_DIR/pulsar-client-cpp pushd tests +export RETRY_FAILED="${RETRY_FAILED:-1}" + if [ -f /gtest-parallel/gtest-parallel ]; then gtest_workers=10 # use nproc to set workers to 2 x the number of available cores if nproc is available @@ -35,13 +37,15 @@ if [ -f /gtest-parallel/gtest-parallel ]; then fi # set maximum workers to 10 gtest_workers=$(( gtest_workers > 10 ? 10 : gtest_workers )) - echo "---- Run unit tests in parallel (workers=$gtest_workers)" + echo "---- Run unit tests in parallel (workers=$gtest_workers) (retry_failed=${RETRY_FAILED})" tests="" if [ $# -eq 1 ]; then tests="--gtest_filter=$1" echo "Running tests: $1" fi - /gtest-parallel/gtest-parallel ./main $tests --workers=$gtest_workers + /gtest-parallel/gtest-parallel $tests --dump_json_test_results=/tmp/gtest_parallel_results.json \ + --workers=$gtest_workers --retry_failed=$RETRY_FAILED -d /tmp \ + ./main RES=$? else ./main From c61d9c5106d50dda84fab0a11bd6e3d421324eeb Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Wed, 21 Apr 2021 17:10:17 +0300 Subject: [PATCH 3/6] Copy logs from the docker container to test-logs directory --- pulsar-client-cpp/docker-tests.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pulsar-client-cpp/docker-tests.sh b/pulsar-client-cpp/docker-tests.sh index 651e5285cc1ff..3dd31f227f98e 100755 --- a/pulsar-client-cpp/docker-tests.sh +++ b/pulsar-client-cpp/docker-tests.sh @@ -42,7 +42,8 @@ echo "---- Testing Pulsar C++ client using image $IMAGE (type --help for more op docker pull $IMAGE -DOCKER_CMD="docker run -i -v $ROOT_DIR:/pulsar $IMAGE" +CONTAINER_LABEL="pulsartests=$$" +DOCKER_CMD="docker run -it -l $CONTAINER_LABEL -v $ROOT_DIR:/pulsar $IMAGE" for args in "$@" @@ -58,4 +59,22 @@ done # Start 2 Pulsar standalone instances (one with TLS and one without) # and execute the tests +set +e $DOCKER_CMD bash -c "cd /pulsar/pulsar-client-cpp && ./run-unit-tests.sh ${tests}" +RES=$? +if [ $RES -ne 0 ]; then + ( + cd "$ROOT_DIR" + mkdir -p test-logs + cd test-logs + container_id=$(docker ps -a -q --filter "label=$CONTAINER_LABEL") + if [ -n "$container_id" ]; then + # copy logs from the container that ran the tests + docker commit $container_id pulsartests/$container_id + docker run -i --rm pulsartests/$container_id \ + bash -c "cd /tmp; tar zcf - gtest-parallel-logs gtest_parallel_results.json pulsar-test-dist/logs" \ + | tar zxvf - + fi + ) +fi +exit $RES \ No newline at end of file From 3e706a5c9e9d255bed33a117bae46992b92f78cc Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Wed, 21 Apr 2021 17:42:50 +0300 Subject: [PATCH 4/6] disable color output by default --- pulsar-client-cpp/docker-tests.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pulsar-client-cpp/docker-tests.sh b/pulsar-client-cpp/docker-tests.sh index 3dd31f227f98e..ad0809f47efad 100755 --- a/pulsar-client-cpp/docker-tests.sh +++ b/pulsar-client-cpp/docker-tests.sh @@ -43,7 +43,8 @@ echo "---- Testing Pulsar C++ client using image $IMAGE (type --help for more op docker pull $IMAGE CONTAINER_LABEL="pulsartests=$$" -DOCKER_CMD="docker run -it -l $CONTAINER_LABEL -v $ROOT_DIR:/pulsar $IMAGE" +export GTEST_COLOR=${GTEST_COLOR:-no} +DOCKER_CMD="docker run -e GTEST_COLOR -it -l $CONTAINER_LABEL -v $ROOT_DIR:/pulsar $IMAGE" for args in "$@" @@ -60,7 +61,11 @@ done # Start 2 Pulsar standalone instances (one with TLS and one without) # and execute the tests set +e -$DOCKER_CMD bash -c "cd /pulsar/pulsar-client-cpp && ./run-unit-tests.sh ${tests}" +DISABLE_COLOR_OUTPUT="" +if [ "$GTEST_COLOR" = "no" ]; then + DISABLE_COLOR_OUTPUT="| cat" +fi +$DOCKER_CMD bash -c "cd /pulsar/pulsar-client-cpp && ./run-unit-tests.sh ${tests} $DISABLE_COLOR_OUTPUT" RES=$? if [ $RES -ne 0 ]; then ( From 10fb4405a20decb53c275d973017b856f8585625 Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Wed, 21 Apr 2021 18:10:03 +0300 Subject: [PATCH 5/6] Upload test-logs directory if job fails --- .github/workflows/ci-cpp.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci-cpp.yaml b/.github/workflows/ci-cpp.yaml index 5f8971120e67d..9b3decd5b648b 100644 --- a/.github/workflows/ci-cpp.yaml +++ b/.github/workflows/ci-cpp.yaml @@ -102,3 +102,11 @@ jobs: - name: run c++ tests if: ${{ steps.changes.outputs.all_count }} > ${{ steps.changes.outputs.docs_count }} run: pulsar-client-cpp/docker-tests.sh + + - name: Upload test-logs + uses: actions/upload-artifact@v2 + if: failure() + continue-on-error: true + with: + name: test-logs + path: test-logs \ No newline at end of file From adfe8656731e142be8e44bfcf3c61da3c8793c83 Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Wed, 21 Apr 2021 18:53:53 +0300 Subject: [PATCH 6/6] Remove "-t" parameter --- pulsar-client-cpp/docker-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pulsar-client-cpp/docker-tests.sh b/pulsar-client-cpp/docker-tests.sh index ad0809f47efad..79a6ded9b2937 100755 --- a/pulsar-client-cpp/docker-tests.sh +++ b/pulsar-client-cpp/docker-tests.sh @@ -44,7 +44,7 @@ docker pull $IMAGE CONTAINER_LABEL="pulsartests=$$" export GTEST_COLOR=${GTEST_COLOR:-no} -DOCKER_CMD="docker run -e GTEST_COLOR -it -l $CONTAINER_LABEL -v $ROOT_DIR:/pulsar $IMAGE" +DOCKER_CMD="docker run -e GTEST_COLOR -i -l $CONTAINER_LABEL -v $ROOT_DIR:/pulsar $IMAGE" for args in "$@"