aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/cache/object_test.go
diff options
context:
space:
mode:
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