Skip to content

Commit c68778d

Browse files
authored
Merge pull request #7364 from guggero/itest-coverage
Add test coverage for integration tests
2 parents f523f52 + 39b7f1c commit c68778d

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

Diff for: .github/workflows/main.yml

+23-4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ jobs:
225225
if: matrix.unit_type == 'btcd unit-cover'
226226
with:
227227
path-to-profile: coverage.txt
228+
flag-name: 'unit'
228229
parallel: true
229230

230231

@@ -241,13 +242,13 @@ jobs:
241242
matrix:
242243
include:
243244
- name: btcd
244-
args: backend=btcd
245+
args: backend=btcd cover=1
245246
- name: bitcoind
246-
args: backend=bitcoind
247+
args: backend=bitcoind cover=1
247248
- name: bitcoind-notxindex
248249
args: backend="bitcoind notxindex"
249250
- name: bitcoind-rpcpolling
250-
args: backend="bitcoind rpcpolling"
251+
args: backend="bitcoind rpcpolling" cover=1
251252
- name: bitcoind-etcd
252253
args: backend=bitcoind dbbackend=etcd
253254
- name: bitcoind-postgres
@@ -259,7 +260,7 @@ jobs:
259260
- name: bitcoind-sqlite-nativesql
260261
args: backend=bitcoind dbbackend=sqlite nativesql=true
261262
- name: neutrino
262-
args: backend=neutrino
263+
args: backend=neutrino cover=1
263264
steps:
264265
- name: git checkout
265266
uses: actions/checkout@v3
@@ -276,6 +277,14 @@ jobs:
276277
- name: run ${{ matrix.name }}
277278
run: make itest-parallel ${{ matrix.args }}
278279

280+
- name: Send coverage
281+
if: ${{ contains(matrix.args, 'cover=1') }}
282+
uses: shogo82148/actions-goveralls@v1
283+
with:
284+
path-to-profile: coverage.txt
285+
flag-name: 'itest-${{ matrix.name }}'
286+
parallel: true
287+
279288
- name: Zip log files on failure
280289
if: ${{ failure() }}
281290
timeout-minutes: 5 # timeout after 5 minute
@@ -401,3 +410,13 @@ jobs:
401410

402411
- name: release notes check
403412
run: scripts/check-release-notes.sh
413+
414+
# Notify about the completion of all coverage collecting jobs.
415+
finish:
416+
if: ${{ always() }}
417+
needs: [unit-test, ubuntu-integration-test]
418+
runs-on: ubuntu-latest
419+
steps:
420+
- uses: shogo82148/actions-goveralls@v1
421+
with:
422+
parallel-finished: true

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ itest/.minerlogs
3838
itest/lnd-itest
3939
itest/btcd-itest
4040
itest/.logs-*
41+
itest/cover
4142

4243
cmd/cmd
4344
*.key

Diff for: Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ build:
111111
build-itest:
112112
@$(call print, "Building itest btcd and lnd.")
113113
CGO_ENABLED=0 $(GOBUILD) -tags="integration" -o itest/btcd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(BTCD_PKG)
114-
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/lnd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(PKG)/cmd/lnd
114+
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" $(ITEST_COVERAGE) -o itest/lnd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(PKG)/cmd/lnd
115115

116116
@$(call print, "Building itest binary for ${backend} backend.")
117117
CGO_ENABLED=0 $(GOTEST) -v ./itest -tags="$(DEV_TAGS) $(RPC_TAGS) integration $(backend)" -c -o itest/itest.test$(EXEC_SUFFIX)
@@ -198,6 +198,7 @@ itest-only: db-instance
198198
@$(call print, "Running integration tests with ${backend} backend.")
199199
rm -rf itest/*.log itest/.logs-*; date
200200
EXEC_SUFFIX=$(EXEC_SUFFIX) scripts/itest_part.sh 0 1 $(TEST_FLAGS) $(ITEST_FLAGS)
201+
$(COLLECT_ITEST_COVERAGE)
201202

202203
#? itest: Build and run integration tests
203204
itest: build-itest itest-only
@@ -210,6 +211,7 @@ itest-parallel: build-itest db-instance
210211
@$(call print, "Running tests")
211212
rm -rf itest/*.log itest/.logs-*; date
212213
EXEC_SUFFIX=$(EXEC_SUFFIX) scripts/itest_parallel.sh $(ITEST_PARALLELISM) $(NUM_ITEST_TRANCHES) $(TEST_FLAGS) $(ITEST_FLAGS)
214+
$(COLLECT_ITEST_COVERAGE)
213215

214216
#? itest-clean: Kill all running itest processes
215217
itest-clean:

Diff for: make/testing_flags.mk

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ DEV_TAGS = dev
22
RPC_TAGS = autopilotrpc chainrpc invoicesrpc neutrinorpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc
33
LOG_TAGS =
44
TEST_FLAGS =
5-
ITEST_FLAGS =
5+
ITEST_FLAGS =
6+
ITEST_COVERAGE =
7+
COLLECT_ITEST_COVERAGE =
68
EXEC_SUFFIX =
79
COVER_PKG = $$(go list -deps -tags="$(DEV_TAGS)" ./... | grep '$(PKG)' | grep -v lnrpc)
810
NUM_ITEST_TRANCHES = 4
@@ -77,6 +79,12 @@ ifneq ($(tags),)
7779
DEV_TAGS += ${tags}
7880
endif
7981

82+
# Enable integration test coverage (requires Go >= 1.20.0).
83+
ifneq ($(cover),)
84+
ITEST_COVERAGE = -cover
85+
COLLECT_ITEST_COVERAGE = go tool covdata textfmt -i=itest/cover -o coverage.txt
86+
endif
87+
8088
# Define the log tags that will be applied only when running unit tests. If none
8189
# are provided, we default to "nolog" which will be silent.
8290
ifneq ($(log),)

Diff for: scripts/itest_part.sh

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ shift
1616
EXEC="$WORKDIR"/itest.test"$EXEC_SUFFIX"
1717
LND_EXEC="$WORKDIR"/lnd-itest"$EXEC_SUFFIX"
1818
BTCD_EXEC="$WORKDIR"/btcd-itest"$EXEC_SUFFIX"
19+
export GOCOVERDIR="$WORKDIR/cover"
20+
mkdir -p "$GOCOVERDIR"
1921
echo $EXEC -test.v "$@" -logoutput -logdir=.logs-tranche$TRANCHE -lndexec=$LND_EXEC -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE
2022

2123
# Exit code 255 causes the parallel jobs to abort, so if one part fails the

0 commit comments

Comments
 (0)