Skip to content

Commit fb845cf

Browse files
committed
Fix BCCSP race
Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
1 parent 887ff5e commit fb845cf

File tree

6 files changed

+63
-11
lines changed

6 files changed

+63
-11
lines changed

cmd/config/cobra_test_exports.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,17 @@ func UnitTestRunner(
131131
t.Cleanup(cancel)
132132

133133
wg.Add(1)
134-
go func() {
134+
wg.Go(func() {
135135
t.Logf("Starting command: %s", args[0])
136136
defer t.Logf("Command exited: %s", args[0])
137-
defer wg.Done()
138-
_, err := cmd.ExecuteContextC(ctx)
139-
err = connection.FilterStreamRPCError(err)
137+
_, execErr := cmd.ExecuteContextC(ctx)
138+
execErr = connection.FilterStreamRPCError(execErr)
140139
if cmdTest.Err == nil {
141-
assert.NoError(t, err)
142-
} else if assert.Error(t, err) {
143-
assert.Equal(t, cmdTest.Err.Error(), err.Error())
140+
assert.NoError(t, execErr)
141+
} else if assert.Error(t, execErr) {
142+
assert.Equal(t, cmdTest.Err.Error(), execErr.Error())
144143
}
145-
}()
144+
})
146145

147146
assert.Eventually(t, func() bool {
148147
return len(getMissing(cmdTest, cmdStdOut.String(), loggerPath)) == 0

service/verifier/main_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package verifier
8+
9+
import (
10+
"testing"
11+
12+
"github.com/hyperledger/fabric-lib-go/bccsp/factory"
13+
)
14+
15+
func TestMain(m *testing.M) {
16+
_ = factory.InitFactories(nil)
17+
m.Run()
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package policy
8+
9+
import (
10+
"testing"
11+
12+
"github.com/hyperledger/fabric-lib-go/bccsp/factory"
13+
)
14+
15+
func TestMain(m *testing.M) {
16+
_ = factory.InitFactories(nil)
17+
m.Run()
18+
}

service/verifier/policy/policy_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ func TestParsePolicyItem(t *testing.T) {
119119
func TestParseLifecycleEndorsementPolicy(t *testing.T) {
120120
t.Parallel()
121121

122-
// Initialize factory before parallel subtests to avoid data race
123-
require.NotNil(t, factory.GetDefault())
124-
125122
t.Run("valid bundle returns verifier", func(t *testing.T) {
126123
t.Parallel()
127124
bundle, cryptoPath := createTestBundle(t)

service/verifier/verifier_server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111

1212
"github.com/cockroachdb/errors"
13+
"github.com/hyperledger/fabric-lib-go/bccsp/factory"
1314
"github.com/hyperledger/fabric-lib-go/common/flogging"
1415
"github.com/hyperledger/fabric-x-common/api/committerpb"
1516
"golang.org/x/sync/errgroup"
@@ -42,6 +43,7 @@ var (
4243
// New instantiate a new VerifierServer.
4344
func New(config *Config) *Server {
4445
logger.Info("Initializing new verifier server")
46+
_ = factory.InitFactories(nil)
4547
return &Server{
4648
config: config,
4749
metrics: newMonitoring(),

utils/signature/main_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package signature
8+
9+
import (
10+
"testing"
11+
12+
"github.com/hyperledger/fabric-lib-go/bccsp/factory"
13+
)
14+
15+
func TestMain(m *testing.M) {
16+
_ = factory.InitFactories(nil)
17+
m.Run()
18+
}

0 commit comments

Comments
 (0)