Skip to content

Commit

Permalink
Fix go-logging concurrent map read-write bug
Browse files Browse the repository at this point in the history
This bug sometimes fails unit tests because logging are sometimes set up
in parallel.

Added a RWLock to op/go-logging/level.go's moduleLeveled struct
and it RLocks in GetLevel and WLocks at SetLevel

Change-Id: I78e837879fece869af9a5e573930492d439a6e82
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Oct 2, 2016
1 parent 0cfd306 commit 5f9f6a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions core/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strings"
"testing"
"time"

"github.com/op/go-logging"
)

func TestComputeCryptoHash(t *testing.T) {
Expand Down Expand Up @@ -98,3 +100,21 @@ func TestFindMissingElements(t *testing.T) {
}
}
}

// This test checks go-logging is thread safe with regard to
// concurrent SetLevel invocation and log invocations.
// Fails without the concurrency fix (adding RWLock to level.go)
// In case the go-logging will be overwritten and its concurrency fix
// will be regressed, this test should fail.
func TestConcurrencyNotFail(t *testing.T) {
logger := logging.MustGetLogger("test")
go func() {
for i := 0; i < 100; i++ {
logging.SetLevel(logging.Level(logging.DEBUG), "test")
}
}()

for i := 0; i < 100; i++ {
logger.Info("")
}
}
5 changes: 5 additions & 0 deletions vendor/github.com/op/go-logging/level.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f9f6a9

Please sign in to comment.