Commit 5cc0dea7 authored by Matthew Sykes's avatar Matthew Sykes
Browse files

[FAB-11685] avoid data races in shim tests



The shim tests use many go routines and cause the go-logging
infrastructure to be initialized many, many times. This introduces
races.

Avoid the races by making initialization run once and moving the logging
specific test to drive the underlying, unexported method.

Change-Id: I175d103b2965b0813baf588def35e3245b77b004
Signed-off-by: default avatarMatthew Sykes <sykesmat@us.ibm.com>
parent 8db4c585
......@@ -15,6 +15,7 @@ import (
"io/ioutil"
"os"
"strings"
"sync"
"time"
"unicode/utf8"
......@@ -163,10 +164,16 @@ func IsEnabledForLogLevel(logLevel string) bool {
return chaincodeLogger.IsEnabledFor(lvl)
}
var loggingSetup sync.Once
// SetupChaincodeLogging sets the chaincode logging format and the level
// to the values of CORE_CHAINCODE_LOGGING_FORMAT, CORE_CHAINCODE_LOGGING_LEVEL
// and CORE_CHAINCODE_LOGGING_SHIM set from core.yaml by chaincode_support.go
func SetupChaincodeLogging() {
loggingSetup.Do(setupChaincodeLogging)
}
func setupChaincodeLogging() {
// This is the default log config from 1.2
const defaultLogFormat = "%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}"
const defaultLevel = logging.INFO
......
......@@ -493,7 +493,7 @@ func TestSetupChaincodeLogging_shim(t *testing.T) {
viper.Set("chaincode.logging.level", tc.ccLogLevel)
viper.Set("chaincode.logging.shim", tc.shimLogLevel)
SetupChaincodeLogging()
setupChaincodeLogging()
_, ccErr := logging.LogLevel(tc.ccLogLevel)
_, shimErr := logging.LogLevel(tc.shimLogLevel)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment