From 8a5160e1de6568699d2244fc63162b05febf380c Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 26 Jan 2023 11:35:43 +0100 Subject: [PATCH 1/3] multi: add test coverage for integration tests --- .github/workflows/main.yml | 8 +++++++- .gitignore | 1 + Makefile | 4 +++- make/testing_flags.mk | 10 +++++++++- scripts/itest_part.sh | 2 ++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 429b091711..720d2a27e8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -274,7 +274,13 @@ jobs: run: ./scripts/install_bitcoind.sh $BITCOIN_VERSION - name: run ${{ matrix.name }} - run: make itest-parallel ${{ matrix.args }} + run: make itest-parallel ${{ matrix.args }} cover=1 + + - name: Send coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.txt + parallel: true - name: Zip log files on failure if: ${{ failure() }} diff --git a/.gitignore b/.gitignore index 16d33c1423..a44a7b8f50 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ itest/.minerlogs itest/lnd-itest itest/btcd-itest itest/.logs-* +itest/cover cmd/cmd *.key diff --git a/Makefile b/Makefile index 41fabbfccb..3c42cd6cfa 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ build: build-itest: @$(call print, "Building itest btcd and lnd.") CGO_ENABLED=0 $(GOBUILD) -tags="integration" -o itest/btcd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(BTCD_PKG) - CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/lnd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(PKG)/cmd/lnd + CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" $(ITEST_COVERAGE) -o itest/lnd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(PKG)/cmd/lnd @$(call print, "Building itest binary for ${backend} backend.") CGO_ENABLED=0 $(GOTEST) -v ./itest -tags="$(DEV_TAGS) $(RPC_TAGS) integration $(backend)" -c -o itest/itest.test$(EXEC_SUFFIX) @@ -197,6 +197,7 @@ itest-only: db-instance @$(call print, "Running integration tests with ${backend} backend.") rm -rf itest/*.log itest/.logs-*; date EXEC_SUFFIX=$(EXEC_SUFFIX) scripts/itest_part.sh 0 1 $(TEST_FLAGS) $(ITEST_FLAGS) + $(COLLECT_ITEST_COVERAGE) #? itest: Build and run integration tests itest: build-itest itest-only @@ -209,6 +210,7 @@ itest-parallel: build-itest db-instance @$(call print, "Running tests") rm -rf itest/*.log itest/.logs-*; date EXEC_SUFFIX=$(EXEC_SUFFIX) scripts/itest_parallel.sh $(ITEST_PARALLELISM) $(NUM_ITEST_TRANCHES) $(TEST_FLAGS) $(ITEST_FLAGS) + $(COLLECT_ITEST_COVERAGE) #? itest-clean: Kill all running itest processes itest-clean: diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 3fecb073a3..b2db6861c3 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -2,7 +2,9 @@ DEV_TAGS = dev RPC_TAGS = autopilotrpc chainrpc invoicesrpc neutrinorpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc LOG_TAGS = TEST_FLAGS = -ITEST_FLAGS = +ITEST_FLAGS = +ITEST_COVERAGE = +COLLECT_ITEST_COVERAGE = EXEC_SUFFIX = COVER_PKG = $$(go list -deps -tags="$(DEV_TAGS)" ./... | grep '$(PKG)' | grep -v lnrpc) NUM_ITEST_TRANCHES = 4 @@ -77,6 +79,12 @@ ifneq ($(tags),) DEV_TAGS += ${tags} endif +# Enable integration test coverage (requires Go >= 1.20.0). +ifneq ($(cover),) +ITEST_COVERAGE = -cover +COLLECT_ITEST_COVERAGE = go tool covdata textfmt -i=itest/cover -o coverage.txt +endif + # Define the log tags that will be applied only when running unit tests. If none # are provided, we default to "nolog" which will be silent. ifneq ($(log),) diff --git a/scripts/itest_part.sh b/scripts/itest_part.sh index 312e13a019..bdf4ecdf58 100755 --- a/scripts/itest_part.sh +++ b/scripts/itest_part.sh @@ -16,6 +16,8 @@ shift EXEC="$WORKDIR"/itest.test"$EXEC_SUFFIX" LND_EXEC="$WORKDIR"/lnd-itest"$EXEC_SUFFIX" BTCD_EXEC="$WORKDIR"/btcd-itest"$EXEC_SUFFIX" +export GOCOVERDIR="$WORKDIR/cover" +mkdir -p "$GOCOVERDIR" echo $EXEC -test.v "$@" -logoutput -logdir=.logs-tranche$TRANCHE -lndexec=$LND_EXEC -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE # Exit code 255 causes the parallel jobs to abort, so if one part fails the From 7468eb341651d91dcba28241be574af1e0bb043d Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 21 Mar 2024 15:38:48 +0100 Subject: [PATCH 2/3] GitHub: only run cover on some itests, send completion We only want to run the coverage on some select tests, since we don't want to make tests with slow backends even slower. And because we use "parallel: true" when uploading the coverage results, those will only be assembled once we send "parallel-finished: true" using the goveralls action. So we do that with a new "finish" job. --- .github/workflows/main.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 720d2a27e8..5443f6ee3f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -241,13 +241,13 @@ jobs: matrix: include: - name: btcd - args: backend=btcd + args: backend=btcd cover=1 - name: bitcoind - args: backend=bitcoind + args: backend=bitcoind cover=1 - name: bitcoind-notxindex args: backend="bitcoind notxindex" - name: bitcoind-rpcpolling - args: backend="bitcoind rpcpolling" + args: backend="bitcoind rpcpolling" cover=1 - name: bitcoind-etcd args: backend=bitcoind dbbackend=etcd - name: bitcoind-postgres @@ -259,7 +259,7 @@ jobs: - name: bitcoind-sqlite-nativesql args: backend=bitcoind dbbackend=sqlite nativesql=true - name: neutrino - args: backend=neutrino + args: backend=neutrino cover=1 steps: - name: git checkout uses: actions/checkout@v3 @@ -274,9 +274,10 @@ jobs: run: ./scripts/install_bitcoind.sh $BITCOIN_VERSION - name: run ${{ matrix.name }} - run: make itest-parallel ${{ matrix.args }} cover=1 + run: make itest-parallel ${{ matrix.args }} - name: Send coverage + if: ${{ contains(matrix.args, 'cover=1') }} uses: shogo82148/actions-goveralls@v1 with: path-to-profile: coverage.txt @@ -407,3 +408,13 @@ jobs: - name: release notes check run: scripts/check-release-notes.sh + + # Notify about the completion of all coverage collecting jobs. + finish: + if: ${{ always() }} + needs: [unit-test, ubuntu-integration-test] + runs-on: ubuntu-latest + steps: + - uses: shogo82148/actions-goveralls@v1 + with: + parallel-finished: true From 39b7f1c4f4bff9b2b6977cdec283d7978fc49adc Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 25 Mar 2024 14:09:09 +0100 Subject: [PATCH 3/3] GitHub: give tag to each cover job --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5443f6ee3f..6d23cf8d9b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -225,6 +225,7 @@ jobs: if: matrix.unit_type == 'btcd unit-cover' with: path-to-profile: coverage.txt + flag-name: 'unit' parallel: true @@ -281,6 +282,7 @@ jobs: uses: shogo82148/actions-goveralls@v1 with: path-to-profile: coverage.txt + flag-name: 'itest-${{ matrix.name }}' parallel: true - name: Zip log files on failure