Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit a86f35f

Browse files
committed
[FAB-5142] Race condition detection
Change-Id: I9d71b2f7b68ad846cd0ec4ad335db6f95ab61c27 Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent 9c4e429 commit a86f35f

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# depend: installs test dependencies
1010
# unit-test: runs all the unit tests
1111
# integration-test: runs all the integration tests
12+
# race-test: runs tests with race detector
1213
# checks: runs all check conditions (license, spelling, linting)
1314
# clean: stops docker conatainers used for integration testing
1415
# mock-gen: generate mocks needed for testing (using mockgen)
@@ -44,6 +45,9 @@ integration-test: clean depend
4445

4546
integration-tests: integration-test
4647

48+
race-test:
49+
@test/scripts/racedetector.sh
50+
4751
mock-gen:
4852
go get -u github.com/golang/mock/gomock
4953
go get -u github.com/golang/mock/mockgen

pkg/fabric-client/channel/channel_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package channel
99
import (
1010
"fmt"
1111
"net"
12+
"os"
13+
"strconv"
1214
"testing"
1315

1416
"google.golang.org/grpc"
@@ -163,7 +165,14 @@ func TestConcurrentPeers(t *testing.T) {
163165
}
164166

165167
func TestConcurrentOrderers(t *testing.T) {
166-
const numOrderers = 10000
168+
// Determine number of orderers to use - environment can override
169+
const numOrderersDefault = 10000
170+
numOrderersEnv := os.Getenv("TEST_MASSIVE_ORDERER_COUNT")
171+
numOrderers, err := strconv.Atoi(numOrderersEnv)
172+
if err != nil {
173+
numOrderers = numOrderersDefault
174+
}
175+
167176
channel, err := setupMassiveTestChannel(0, numOrderers)
168177
if err != nil {
169178
t.Fatalf("Failed to create massive channel: %s", err)

test/scripts/integration.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
# Environment variables that affect this script:
99
# USE_PREBUILT_IMAGES: Integration tests are run against fabric docker images.
10-
# Can be latest tagged (FALSE) or tags specified in .env (default)
11-
# ARCH: Fabric docker images architecture
10+
# Can be latest tagged (FALSE) or tags specified in .env (default).
11+
# ARCH: Fabric docker images architecture.
1212
# If not set, ARCH defaults to the value specified in .env.
13+
# GOTESTFLAGS: Flags are added to the go test command.
14+
# LDFLAGS: Flags are added to the go test command (example: -ldflags=-s).
1315

1416
# Packages to include in test run
1517
PKGS=`go list github.com/hyperledger/fabric-sdk-go/test/integration/... 2> /dev/null | \
@@ -26,7 +28,7 @@ cd ./test/fixtures && docker-compose up --force-recreate -d
2628

2729
echo "Running integration tests..."
2830
cd ../../
29-
gocov test $LDFLAGS $PKGS -p 1 -timeout=10m | gocov-xml > integration-report.xml
31+
gocov test $GOTESTFLAGS $LDFLAGS $PKGS -p 1 -timeout=10m | gocov-xml > integration-report.xml
3032

3133
if [ $? -eq 0 ]
3234
then

test/scripts/racedetector.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
#
3+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
SCRIPT_PATH=$(dirname "$0")
9+
10+
export GOTESTFLAGS="$GOTESTFLAGS -race -v"
11+
export TEST_MASSIVE_ORDERER_COUNT=2000
12+
$SCRIPT_PATH/unit.sh
13+
$SCRIPT_PATH/integration.sh

test/scripts/unit.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66
#
7+
# Environment variables that affect this script:
8+
# GOTESTFLAGS: Flags are added to the go test command.
9+
# LDFLAGS: Flags are added to the go test command (example: -ldflags=-s).
710

811
set -e
912

@@ -12,4 +15,4 @@ PKGS=`go list github.com/hyperledger/fabric-sdk-go/... 2> /dev/null | \
1215
grep -v /vendor/ | \
1316
grep -v /test/`
1417
echo "Running tests..."
15-
gocov test $LDFLAGS $PKGS -p 1 -timeout=5m | gocov-xml > report.xml
18+
gocov test $GOTESTFLAGS $LDFLAGS $PKGS -p 1 -timeout=5m | gocov-xml > report.xml

0 commit comments

Comments
 (0)