Skip to content

Commit

Permalink
[FAB-5142] Race condition detection
Browse files Browse the repository at this point in the history
Change-Id: I9d71b2f7b68ad846cd0ec4ad335db6f95ab61c27
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Jul 4, 2017
1 parent 9c4e429 commit a86f35f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# depend: installs test dependencies
# unit-test: runs all the unit tests
# integration-test: runs all the integration tests
# race-test: runs tests with race detector
# checks: runs all check conditions (license, spelling, linting)
# clean: stops docker conatainers used for integration testing
# mock-gen: generate mocks needed for testing (using mockgen)
Expand Down Expand Up @@ -44,6 +45,9 @@ integration-test: clean depend

integration-tests: integration-test

race-test:
@test/scripts/racedetector.sh

mock-gen:
go get -u github.com/golang/mock/gomock
go get -u github.com/golang/mock/mockgen
Expand Down
11 changes: 10 additions & 1 deletion pkg/fabric-client/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package channel
import (
"fmt"
"net"
"os"
"strconv"
"testing"

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

func TestConcurrentOrderers(t *testing.T) {
const numOrderers = 10000
// Determine number of orderers to use - environment can override
const numOrderersDefault = 10000
numOrderersEnv := os.Getenv("TEST_MASSIVE_ORDERER_COUNT")
numOrderers, err := strconv.Atoi(numOrderersEnv)
if err != nil {
numOrderers = numOrderersDefault
}

channel, err := setupMassiveTestChannel(0, numOrderers)
if err != nil {
t.Fatalf("Failed to create massive channel: %s", err)
Expand Down
8 changes: 5 additions & 3 deletions test/scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

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

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

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

if [ $? -eq 0 ]
then
Expand Down
13 changes: 13 additions & 0 deletions test/scripts/racedetector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

SCRIPT_PATH=$(dirname "$0")

export GOTESTFLAGS="$GOTESTFLAGS -race -v"
export TEST_MASSIVE_ORDERER_COUNT=2000
$SCRIPT_PATH/unit.sh
$SCRIPT_PATH/integration.sh
5 changes: 4 additions & 1 deletion test/scripts/unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Environment variables that affect this script:
# GOTESTFLAGS: Flags are added to the go test command.
# LDFLAGS: Flags are added to the go test command (example: -ldflags=-s).

set -e

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

0 comments on commit a86f35f

Please sign in to comment.