aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/cache/object_test.go
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2017-08-11 13:21:14 +0200
committerMiguel Molina <miguel@erizocosmi.co>2017-08-11 14:29:52 +0200
commit3fd398852745b218e4346a38c98d95e5e773751d (patch)
tree1689d6c0fdbdad5a1e804b293eba0bdae9fb1a7e /plumbing/cache/object_test.go
parent773841734e11f0f607f6b047235f8527d475538f (diff)
downloadgo-git-3fd398852745b218e4346a38c98d95e5e773751d.tar.gz
fix race condition on ObjectLRU
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'plumbing/cache/object_test.go')
-rw-r--r--plumbing/cache/object_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/plumbing/cache/object_test.go b/plumbing/cache/object_test.go
index 9359455..b38272f 100644
--- a/plumbing/cache/object_test.go
+++ b/plumbing/cache/object_test.go
@@ -1,7 +1,9 @@
package cache
import (
+ "fmt"
"io"
+ "sync"
"testing"
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -67,6 +69,32 @@ func (s *ObjectSuite) TestClear(c *C) {
c.Assert(obj, IsNil)
}
+func (s *ObjectSuite) TestConcurrentAccess(c *C) {
+ var wg sync.WaitGroup
+
+ for i := 0; i < 1000; i++ {
+ wg.Add(3)
+ go func(i int) {
+ s.c.Put(newObject(fmt.Sprint(i), FileSize(i)))
+ wg.Done()
+ }(i)
+
+ go func(i int) {
+ if i%30 == 0 {
+ s.c.Clear()
+ }
+ wg.Done()
+ }(i)
+
+ go func(i int) {
+ s.c.Get(plumbing.NewHash(fmt.Sprint(i)))
+ wg.Done()
+ }(i)
+ }
+
+ wg.Wait()
+}
+
type dummyObject struct {
hash plumbing.Hash
size FileSize