Merge pull request #344 from mrbroll/diff-data-race

Fix #347 - Diff data race
pull/332/merge
Ernesto Jiménez 2016-09-24 14:56:45 +01:00 committed by GitHub
commit c13a3217b3
2 changed files with 38 additions and 1 deletions

View File

@ -18,6 +18,10 @@ import (
"github.com/pmezard/go-difflib/difflib"
)
func init() {
spew.Config.SortKeys = true
}
// TestingT is an interface wrapper around *testing.T
type TestingT interface {
Errorf(format string, args ...interface{})
@ -1001,7 +1005,6 @@ func diff(expected interface{}, actual interface{}) string {
return ""
}
spew.Config.SortKeys = true
e := spew.Sdump(expected)
a := spew.Sdump(actual)

View File

@ -1125,6 +1125,40 @@ func TestDiffEmptyCases(t *testing.T) {
Equal(t, "", diff([]int{1}, []bool{true}))
}
// Ensure there are no data races
func TestDiffRace(t *testing.T) {
t.Parallel()
expected := map[string]string{
"a": "A",
"b": "B",
"c": "C",
}
actual := map[string]string{
"d": "D",
"e": "E",
"f": "F",
}
// run diffs in parallel simulating tests with t.Parallel()
numRoutines := 10
rChans := make([]chan string, numRoutines)
for idx := range rChans {
rChans[idx] = make(chan string)
go func(ch chan string) {
defer close(ch)
ch <- diff(expected, actual)
}(rChans[idx])
}
for _, ch := range rChans {
for msg := range ch {
NotZero(t, msg) // dummy assert
}
}
}
type mockTestingT struct {
}