Skip to content

Commit d8bb207

Browse files
pfi79denyeart
authored andcommitted
fix fail test with cover flag
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent 9336215 commit d8bb207

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

.github/workflows/verify-build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ jobs:
3737
name: Unit Tests
3838
needs: basic-checks
3939
runs-on: ${{ github.repository == 'hyperledger/fabric' && 'fabric-ubuntu-22.04' || 'ubuntu-22.04' }}
40-
env:
41-
GOEXPERIMENT: nocoverageredesign
4240
steps:
4341
- uses: actions/checkout@v4
4442
with:

core/handlers/library/registry_plugin_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func buildPlugin(t *testing.T, dest, pkg string) {
4545
require.NoError(t, err, "Could not build plugin: "+string(output))
4646
}
4747

48-
func TestLoadAuthPlugin(t *testing.T) {
48+
func TestLoadAuthPluginNoCover(t *testing.T) {
4949
if noplugin {
5050
t.Skip("plugins disabled")
5151
}
@@ -65,7 +65,7 @@ func TestLoadAuthPlugin(t *testing.T) {
6565
require.True(t, endorser.invoked, "Expected filter to invoke endorser on invoke")
6666
}
6767

68-
func TestLoadDecoratorPlugin(t *testing.T) {
68+
func TestLoadDecoratorPluginNoCover(t *testing.T) {
6969
if noplugin {
7070
t.Skip("plugins disabled")
7171
}
@@ -86,7 +86,7 @@ func TestLoadDecoratorPlugin(t *testing.T) {
8686
require.True(t, proto.Equal(decoratedInput, testInput), "Expected chaincode input to remain unchanged")
8787
}
8888

89-
func TestEndorsementPlugin(t *testing.T) {
89+
func TestEndorsementPluginNoCover(t *testing.T) {
9090
if noplugin {
9191
t.Skip("plugins disabled")
9292
}
@@ -109,7 +109,7 @@ func TestEndorsementPlugin(t *testing.T) {
109109
require.Equal(t, []byte{1, 2, 3}, output)
110110
}
111111

112-
func TestValidationPlugin(t *testing.T) {
112+
func TestValidationPluginNoCover(t *testing.T) {
113113
if noplugin {
114114
t.Skip("plugins disabled")
115115
}

scripts/run-unit-tests.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ serial_packages=(
1818
"github.com/hyperledger/fabric/gossip/..."
1919
)
2020

21+
no_coverage_packages=(
22+
"github.com/hyperledger/fabric/core/handlers/library"
23+
)
24+
2125
# packages which need to be tested with build tag pkcs11
2226
pkcs11_packages=(
2327
"github.com/hyperledger/fabric/bccsp/factory"
@@ -132,10 +136,18 @@ serial_test_packages() {
132136
fi
133137
}
134138

139+
no_coverage_test_packages() {
140+
local filter
141+
filter=$(package_filter "${no_coverage_packages[@]}")
142+
if [ -n "$filter" ]; then
143+
join_by $'\n' "$@" | grep -E "$filter" || true
144+
fi
145+
}
146+
135147
# "go test" the provided packages. Packages that are not present in the serial package list
136148
# will be tested in parallel
137149
run_tests() {
138-
local -a flags=("-cover")
150+
local -a flags
139151
if [ -n "${VERBOSE}" ]; then
140152
flags+=("-v")
141153
fi
@@ -153,21 +165,33 @@ run_tests() {
153165
local -a serial
154166
while IFS= read -r pkg; do serial+=("$pkg"); done < <(serial_test_packages "$@")
155167
if [ "${#serial[@]}" -ne 0 ]; then
156-
go test "${flags[@]}" -failfast -tags "$GO_TAGS" "${serial[@]}" -short -p 1 -timeout=20m
168+
go test -cover "${flags[@]}" -failfast -tags "$GO_TAGS" "${serial[@]}" -short -p 1 -timeout=20m
157169
fi
158170

159171
local -a parallel
160172
while IFS= read -r pkg; do parallel+=("$pkg"); done < <(parallel_test_packages "$@")
161173
if [ "${#parallel[@]}" -ne 0 ]; then
162-
go test "${flags[@]}" "${race_flags[@]}" -tags "$GO_TAGS" "${parallel[@]}" -short -timeout=20m
174+
go test -cover "${flags[@]}" "${race_flags[@]}" -tags "$GO_TAGS" "${parallel[@]}" -short -timeout=20m -skip=NoCover
175+
fi
176+
177+
# The -cover flag changes the import table of the test and the plugin
178+
# so that they cannot interact with each other.
179+
# In the name of tests that work with plugins we added the suffix NoCover
180+
# and do not run these tests with the -cover flag.
181+
# We run such tests separately, without the -cover flag.
182+
local -a no_coverage
183+
while IFS= read -r pkg; do no_coverage+=("$pkg"); done < <(no_coverage_test_packages "$@")
184+
if [ "${#no_coverage[@]}" -ne 0 ]; then
185+
echo "test with no coverage"
186+
go test "${flags[@]}" "${race_flags[@]}" -tags "$GO_TAGS" "${no_coverage[@]}" -short -timeout=20m -run=NoCover
163187
fi
164188
}
165189
}
166190

167191
# "go test" the provided packages and generate code coverage reports.
168192
run_tests_with_coverage() {
169193
# run the tests serially
170-
time go test -p 1 -cover -coverprofile=profile_tmp.cov -tags "$GO_TAGS" "$@" -timeout=20m
194+
time go test -p 1 -cover -coverprofile=profile_tmp.cov -tags "$GO_TAGS" "$@" -timeout=20m -skip=NoCover
171195
tail -n +2 profile_tmp.cov >> profile.cov && rm profile_tmp.cov
172196
}
173197

0 commit comments

Comments
 (0)