mirror of
https://github.com/golang/go
synced 2024-10-03 08:11:27 -06:00
go/token: add test for concurrent use of FileSet.Pos
Update #4354. Add a test to expose the race in the FileSet position cache. R=dvyukov, gri CC=fullung, golang-dev https://golang.org/cl/6940078
This commit is contained in:
parent
4ea8538c7f
commit
4e406a2372
@ -6,6 +6,8 @@ package token
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -179,3 +181,26 @@ func TestFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue 4345. Test concurrent use of FileSet.Pos does not trigger a
|
||||||
|
// race in the FileSet position cache.
|
||||||
|
func TestFileSetRace(t *testing.T) {
|
||||||
|
fset := NewFileSet()
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
fset.AddFile(fmt.Sprintf("file-%d", i), fset.Base(), 1031)
|
||||||
|
}
|
||||||
|
max := int32(fset.Base())
|
||||||
|
var stop sync.WaitGroup
|
||||||
|
r := rand.New(rand.NewSource(7))
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
r := rand.New(rand.NewSource(r.Int63()))
|
||||||
|
stop.Add(1)
|
||||||
|
go func() {
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
fset.Position(Pos(r.Int31n(max)))
|
||||||
|
}
|
||||||
|
stop.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
stop.Wait()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user